Using CryptoJS for AES decryption

This tutorial is amazing, it runs through CryptoJS, but unfortunately doesn’t make clear the  most important point. This code demonstrates AES encryption and decryption:

var key = CryptoJS.lib.WordArray.random(16);
var iv = CryptoJS.lib.WordArray.random(16);
var encrypted = CryptoJS.AES.encrypt("Message", key.toString(), { iv: iv.toString() });
var decrypted = CryptoJS.AES.decrypt(encrypted.toString(), key.toString(), { iv: iv.toString() });

But if you can’t get the decrypted content at the end, you have to do this:


I’m sure this will save a lot of heartache.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s