How Encrypt With Aes Cbc Zero Padding In Javascript And Decrypt With Java
Solution 1:
In the JavaScript-code key and iv have to be passed as WordArrays
. For this purpose CryptoJS
provides conversion functions:
var key = CryptoJS.enc.Latin1.parse("CLAVE00000000000");
var iv = CryptoJS.enc.Latin1.parse("VECTOR0000000000");
If the key is passed as a string (as it is the case in the posted code), it is treated as a passphrase and used to derive a key and IV (see here, section The Cipher Input).
Furthermore, in the JavaScript-code Zero-Byte-Padding must be replaced by Pkcs7-Padding (padding: CryptoJS.pad.Pkcs7
instead of padding: CryptoJS.pad.ZeroPadding
) in the encrypt
- and decrypt
-call.
Then the encryption of the JavaScript-code corresponds to that of the Java-code (sEAtASy0J3+Ya3g+Afcj3Q==
for the used message, key and IV).
The replacing of the padding is a guess because the encrypt
- and decrypt
-methods of the Java-code have not been posted, so that a direct check is not possible. However, with regard to the same encryption when switching to Pkcs7, this should be true.
Post a Comment for "How Encrypt With Aes Cbc Zero Padding In Javascript And Decrypt With Java"