问题
I am trying to adapt the following solution into my Node application to decrypt a field sent from the client browser via POST:
How to decrypt with CryptoJS using AES?
Seem to be going round in circles in getting values to match in the console. The values for the encryption of 'hello' match both applied from Server and from client (sending 'hello' however there is now no decryption value showing for either.
The server side code in a Node POST Route:
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" }'));
});
Any help appreciated!
来源:https://stackoverflow.com/questions/27174971/how-to-decrypt-a-field-sent-from-client-to-node-server-using-cryptojs