【发布时间】:2019-11-07 00:21:38
【问题描述】:
我在 HTML 中的 NativeJS 中使用 cryptoJs。但是当我用 aesDecrypt(decrypted,key) 对 txt 进行解密时,它就不起作用了。我已经尝试了许多其他密码,但它仍然不起作用。你们会查看下面的代码并给我一些建议吗?
我在后端尝试了许多密码(如 aes-192-ecb、aes-256-ecb),但仍然无法正常工作。它报告:错误加密错误。
Front code: encrypt the txt and send to backend.
function aesEncrypt(data, key) {
key = CryptoJS.enc.Utf8.parse(key);
let encrypted = CryptoJS.AES.encrypt(data, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
Backend code: decrypt the txt sent from front.
function aesDecrypt(encrypted, key) {
const decipher = crypto.createDecipher('aes192', key);
let decrypted = decipher.update(encrypted, 'binary', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
【问题讨论】:
标签: cryptojs