我的客户端代码:
data.username = CryptoJS.AES.encrypt(user.username, "password");
data.password = CryptoJS.AES.encrypt(user.password, "password");然后我将“数据”发送到服务器,即express.js。
var user = req.body;
var decipher = crypto.createDecipher('aes256', "password");
var decrypted = decipher.update(user.username, 'hex', 'utf-8');
decrypted += decipher.final('utf-8'); 我得到了这个错误:
Error: DecipherInit error
at new Decipher (crypto.js:368:17)
at Object.Decipher (crypto.js:365:12)发布于 2015-02-06 08:11:03
带有密码的CryptoJS‘encrypt函数使用相同的EVP_BytesToKey函数node.js’createCipher,其重要区别在于CryptoJS使用随机盐来派生,而节点不 (强调挖掘):
注意: createCipher使用OpenSSL函数EVP_BytesToKey派生键,其中摘要算法设置为MD5、一次迭代和无salt。
您可以在节点中直接使用CryptoJS,这是可能的,因为CryptoJS没有任何依赖关系,或者您自己在两端进行密钥派生并使用crypto.createCipheriv。如果您执行前者,则必须将用户名和密码加密的盐类额外传递给节点。
请注意,data.username是包含salt和IV的CryptoJS cipherParams对象,但是当您用data.username.toString()将其转换为字符串时,salt不再包含,但IV包含。这不是要放入node.js函数中的node.js。发送data.username.ciphertext代替。
https://stackoverflow.com/questions/28359128
复制相似问题