我正在尝试将以下解决方案调整到我的Node应用程序中,以解密通过POST从客户端浏览器发送的字段:
How to decrypt with CryptoJS using AES?
似乎要在控制台中获取要匹配的值。加密'你好'匹配从服务器和客户端应用的两者(发送'你好'但是现在没有显示任何解密值。
节点POST路由中的服务器端代码:
var ENC_KEY = "c2VjcmV0"; //'secret'
app.post('/hello', function (req, res) {
console.log('POST /hello');
var key = CryptoJS.enc.Base64.parse(ENC_KEY);
console.log('key: ' + key);
console.log('client msg ("hello"): ' + req.body.msg_hello);
var encrypted = CryptoJS.AES.encrypt("hello", key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
console.log('server msg "hello" encrypted to: ' + encrypted);
var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
console.log('server msg decrypted: ' + hex2a(decrypted));
var decryptedClient = CryptoJS.AES.decrypt(req.body.msg_hello, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
console.log('client msg decrypted: ' + hex2a(decryptedClient));
res.end(JSON.stringify('{ response: "response" }'));
});
任何帮助表示赞赏!