I'm trying to encrypt a message in javascript (using crypto-js library) and to decrypt it in java.
This is the javascript code:
var key = CryptoJS.enc.Utf8.parse(aesPassword);
var ive = CryptoJS.enc.Utf8.parse(aesIv);
var encryptedData = CryptoJS.AES.encrypt(dataToEncrypt, key, {mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7, iv: ive});
And this is the java code:
final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
final SecretKeySpec key = new SecretKeySpec(aesPassword().getBytes("UTF-8"), "AES");
cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(aesIv().getBytes("UTF-8")));
byte[] decrypted = cipher.doFinal(DatatypeConverter.parseBase64Binary(message));
But when I try to decrypt in Java this exception is thrown: javax.crypto.BadPaddingException: Given final block not properly padded
password: 6h2faBePVxpgyFSN iv: NKOzRKrmEMKs1kE4 data to encrypt: "{token: cMGOIrYlJm9lPhPW}"
Any help?
Thanks in advance