使用 jquery 的 AES 加密
AES encryption with jquery
我正在尝试使用 CryptoJS 库在本地加密和解密 AES。
我有来自 example:
的代码
var encrypted = CryptoJS.AES.encrypt(mess, pass);
var decrypted = CryptoJS.AES.decrypt(encrypted, pass);
但是 decrypted
变量没有返回 mess
变量?这是为什么?
请看JSFiddle?
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.
将decrypted
替换为decrypted.toString(CryptoJS.enc.Utf8))
,参见updated fiddle。
我正在尝试使用 CryptoJS 库在本地加密和解密 AES。
我有来自 example:
var encrypted = CryptoJS.AES.encrypt(mess, pass);
var decrypted = CryptoJS.AES.decrypt(encrypted, pass);
但是 decrypted
变量没有返回 mess
变量?这是为什么?
请看JSFiddle?
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.
将decrypted
替换为decrypted.toString(CryptoJS.enc.Utf8))
,参见updated fiddle。