[英]crypto-js aes can't decrypt what it encrypted
Hello I'm trying to decrypt a encrypted aes string with crypto-js but it seems like it doesn't work right. 您好我正在尝试使用crypto-js解密加密的aes字符串,但它似乎无法正常工作。
I'm using: 我正在使用:
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script>
var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");
var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase");
</script>
But my results are: 但我的结果是:
encrypted: U2FsdGVkX19whKq54yOQt3l1erbtEtn/M0qJjAH+E/E=
decrypted: 4d657373616765
My expectation was the it returns back "Message". 我的期望是它返回“消息”。 What am I missing? 我错过了什么?
The return type of all CryptoJS.<blockcipher>.decrypt()
functions is a WordArray
which is the native representation of binary data in CryptoJS. 所有CryptoJS.<blockcipher>.decrypt()
函数的返回类型是一个WordArray
,它是WordArray
中二进制数据的本机表示形式。 When you force it to be printed (automatically calling toString()
), the binary data that it contains will be Hex encoded. 当您强制打印它时(自动调用toString()
),它包含的二进制数据将是十六进制编码的。
If you want to have a different encoding, then you need to specify it. 如果要使用不同的编码,则需要指定它。 Here are some examples: 这里有些例子:
console.log(decrypted.toString()); // Hex encoded
console.log(decrypted.toString(CryptoJS.enc.Hex)); // Hex encoded
console.log(CryptoJS.enc.Hex.stringify(decrypted)); // Hex encoded
console.log(decrypted.toString(CryptoJS.enc.Utf8)); // UTF-8 encoded
console.log(CryptoJS.enc.Utf8.stringify(decrypted)); // UTF-8 encoded
console.log(decrypted.toString(CryptoJS.enc.Base64)); // Base64 encoded
console.log(CryptoJS.enc.Base64.stringify(decrypted)); // Base64 encoded
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.