AES Encrypt and decrypt from Hex
Author: andrepcgCreated Jan 13, 2018Updated May 18, 2026
What is wrong with the following piece of code?
var key = '123';
// Encrypt
var ciphertext = CryptoJS.AES.encrypt('my message', key);
var cypherString = ciphertext.toString(CryptoJS.format.Hex)
// Decrypt
var bytes = CryptoJS.AES.decrypt(cypherString, key, {format: CryptoJS.format.Hex });
var plaintext = bytes.toString();plaintext is always an empty string when it should output 'my message'
Source: brix/crypto-js