Decryption in Crypto-JS gives numerical hexadecimal output instead of the original plaintext string

I compiled a simple test using an example from the Crypto-JS Source Site in Google code :

In the page title:

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>

In the Javascript function:

var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");
var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase");

alert('encrypted: '+encrypted+'  decrypted: '+decrypted);

but conclusion:

encrypted: U2FsdGVkX19hsNqFBS5xcUoVBCu/hPHepEwZchqnUVU=
decrypted: 4d657373616765

image of decrypted output

What am I missing?

+4
source share
1 answer
decrypted.toString(CryptoJS.enc.Utf8) // "Message"

See https://code.google.com/p/crypto-js/#The_Hasher_Output

The hash that you return is not yet a string. This is a WordArray object . When you use a WordArray in the context of a string, it is automatically converted to a hex string .

WordArray , toString encoder.

+5

All Articles