【发布时间】:2020-06-07 16:24:23
【问题描述】:
我在 Node.js 中使用以下函数来加密/解密字符串:
var crypto = require('crypto');
var algorithm = 'aes-256-ctr';
function encrypt(text) {
var cipher = crypto.createCipher(algorithm, password);
try {
var crypted = cipher.update(text, 'utf8', 'hex');
crypted += cipher.final('hex');
} catch (e) {
return;
}
return crypted;
}
function decrypt(text) {
var decipher = crypto.createDecipher(algorithm, password);
try {
var dec = decipher.update(text, 'hex', 'utf8');
dec += decipher.final('utf8');
} catch (e) {
return;
}
return dec;
}
(密码与编码文本分开存储)。新版nodejs/crypt包报错:
(node:5212) [DEP0106] DeprecationWarning: crypto.createDecipher is deprecated.
如何重写它来升级我的源代码?
【问题讨论】:
标签: node.js encryption