我正在尝试在我的 NodeJS 应用程序中使用本机加密模块,但我不断收到弃用消息:
(节点:26)弃用警告:不推荐使用未指定摘要的 crypto.pbkdf2。请指定摘要
我知道这是由于期望摘要向前推进的更改集: https ://github.com/nodejs/node/pull/4047
但是,据我所见,我的代码完全遵循文档中概述的语法。其他人看到我在这里做错了吗?
function verify (password, expected, callback) {
const combined = Buffer.from(expected, 'base64')
const saltBytes = combined.readUInt32BE(0)
const hashBytes = combined.length - saltBytes - 8
const iterations = combined.readUInt32BE(4)
const salt = combined.slice(8, saltBytes + 8)
const hash = combined.toString('binary', saltBytes + 8)
return crypto.pbkdf2(password, salt, iterations, hashBytes, 'sha512', (err, verify) => {
if (err) return callback(err, false)
return callback(null, verify.toString('binary') === hash)
})
}
注意:如果有任何区别,这是在 node:6 的 slim 版本中执行的