I have a simple nodeJS program to encrypt plaintext:
var crypto = require("crypto");
var compatEnc = crypto.createCipher("aes-256-cbc", "password");
compatCrypted = compatEnc.update("Message", "utf8", "hex");
compatCrypted += compatEnc.final("hex");
console.log(compatCrypted);
// 0293cf0bdf5323cff809ba406ffc8283
I try to decrypt 0293cf0bdf5323cff809ba406ffc8283 on the browser
<!doctype html>
<html>
<body>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core-min.js"></script>
<script>
var nosalt = CryptoJS.lib.WordArray.random(0);
// { salt : null } will generate random salt
var enc = CryptoJS.AES.decrypt("0293cf0bdf5323cff809ba406ffc8283", "password",
{ salt: nosalt });
console.log(CryptoJS.enc.Utf8.stringify(enc));
</script>
</body>
</html>
The output is blank. Can you tell me what is wrong with my decryption code? Thanks.
CryptoJS doesn't know that your encrypted text is hex-encoded.
Convert it to a WordArray first using CryptoJS.enc.Hex.parse(...);.