I dealing with cryptojs and want to try a simple example with aes
var encrypted = CryptoJS.AES.encrypt("TEST_TEXT", '9021D105A446', {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
var decrypt = CryptoJS.AES.decrypt(encrypted, '9021D105A446', {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
console.log(decrypt.toString(CryptoJS.enc.Utf8));//Yeah! TEST_TEXT output as expected
Now I give a try with encrypted in base64, but not output as expected
var encryptedText = encrypted.ciphertext.toString(CryptoJS.enc.Base64)
var encrypted2 = CryptoJS.enc.Base64.parse(encryptedText);
var decrypt2 = CryptoJS.AES.decrypt(encrypted2, '9021D105A446', {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
console.log(decrypt2.toString(CryptoJS.enc.Utf8));// Ops! empty output
Do you know something went wrong with decryption in 2nd example?
Another question, every I run example 1, the encryptedText
was difference from previous running. Is this normal behavior?
Fiddle update : https://jsfiddle.net/n6wL9a40/