Given this code:
var s = "125\xb5\xb5$8"
/* var s = "AAAA" */
var key = CryptoJS.enc.Utf8.parse(s)
var iv = CryptoJS.enc.Utf8.parse(s)
var plain = "Very secret message!"
var encrypted = CryptoJS.AES.encrypt(plain, key, {
keySize: 16,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
var encryptedb64 = encrypted.toString()
console.log("encrypted:", encryptedb64)
var decrypted = CryptoJS.AES.decrypt(encryptedb64, key, {
keySize: 16,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
console.log("decrypted:", decrypted.toString(CryptoJS.enc.Utf8))
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
I get this output (not expected):
"encrypted:", "W2dFmOY22wp2W1ayCa1xmk3EwaxG/H+LKkgnADKAYmY="
"decrypted:", ""
When changing the key to "AAAA" I get this output (as expected):
"encrypted:", "OAmNRtxYfJIFEq4VK4xPievfuXIIfEV+48yHBqVexWI="
"decrypted:", "Very secret message!"
I understand that key & iv should NOT be the same and should NOT be static, but that's not the point here.
I already have strings encrypted with those parameters and need to decrypt them. I expected this to work. If the encryption is giving me back a result, then decryption should work when using the same parameters.