Currently, I am facing an issue with encrypting and decrypting data using AES encryption. In my code, I am encrypting the data in javascript using crypto.js and trying to decrypt it in Java.
Encryption and decryption work correctly when done in either javascript or java individually. However, when I attempt to encrypt in javascript and then decrypt in java, I encounter the following error:
javax.crypto.BadPaddingException: Given final block not properly padded at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:966)
Here is a snippet of my JSCode for encryption:
var keyHex = CryptoJS.enc.Utf8.parse('584771624934175587013168');
var iv = CryptoJS.enc.Hex.parse('000000000000000000000000');
var encrypted = CryptoJS.AES.encrypt('1111', keyHex, {
iv:iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
console.log('encryptByAES key: ',encrypted.toString());
And this is a snippet of my java code for decryption:
String key = "584771624934175587013168";
String plainText = "1111";
// Methods for encryption and decryption using AES
How can I resolve this decryption issue? Any assistance would be greatly appreciated!