Search code examples
javascriptencryptionaescryptojs

How to decrypt AES with a known KEY and IV using Javascript?


I'm trying to learn CryptoJS using https://code.google.com/p/crypto-js/ It shows how to encrypt with AES but it does not how how to decrypt using both KEY and IV. I'm looking at the below code.

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script>
var key = CryptoJS.enc.Hex.parse('000102030405060708090a0b0c0d0e0f');
var iv  = CryptoJS.enc.Hex.parse('101112131415161718191a1b1c1d1e1f');

var encrypted = CryptoJS.AES.encrypt("Message", key, { iv: iv });

I have tried the below code:

var decrypted = CryptoJS.AES.decrypt(encrypted, key, { iv: iv });

However, it gives me the wrong plain text. Anyone know what I'm doing wrong?

The output I receive is:

4d657373616765

The correct plain text should obviously be:

Message

Am I misunderstanding something?


Solution

  • ASCII ;-) http://www.italysoft.com/utility/converters/asciifull.gif

    The output are binary ASCII characters.

    4d = M 65 = e

    etc...