I have the following cryptojs based javascript encryption/decryption functions which works perfectly fine.
I use a random salt, random iv value and a specific password
This part of your code is wrong:
KeySpec keySpec = new PBEKeySpec(password.toCharArray(), saltBytes, 100, 128/32);
//->---------------------------------------------------------------------^^^^^^^
The 128/32
value is erroneous. You need either 128
, 192
or 256
. Currently you have the equivalent of 4
, which seems to result in no output at all from the PBKDF2 function.
Also, in Java you should use DatatypeConverter.parseHexBinary(), or similar, to convert hex into bytes. Currently you are just calling getBytes()
which isn't right.
Finally, you need to specify CBC mode and PKCS#5 padding in order to match your Javascript code. So change the line to:
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");