我使用 Crypto-JS source site at Google code 中的示例进行了简单测试:
在页眉中:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
在 Javascript 函数中:
var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");
var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase");
alert('encrypted: '+encrypted+' decrypted: '+decrypted);
但是输出是:
encrypted: U2FsdGVkX19hsNqFBS5xcUoVBCu/hPHepEwZchqnUVU=
decrypted: 4d657373616765
我错过了什么?
最佳答案
decrypted.toString(CryptoJS.enc.Utf8) // "Message"
参见 https://code.google.com/p/crypto-js/#The_Hasher_Output
The hash you get back isn't a string yet. It's a WordArray object. When you use a WordArray object in a string context, it's automatically converted to a hex string.
You can convert a WordArray object to other formats by explicitly calling the toString method and passing an encoder.
关于javascript - Crypto-JS 中的解密给出数字十六进制输出而不是原始明文字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26259009/