2

我正在尝试在我的 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 版本中执行的

4

1 回答 1

0

经过多次挖掘,我终于弄明白了。它与上面的代码段无关。我正在使用目前版本为 4.0.0的Iron模块。当前发布的版本没有为摘要传递参数,这会导致生成警告消息。

他们已经提交了代码来纠正这个问题,但它还没有发布。这应该很快就会自行解决。

于 2016-05-07T06:10:36.947 回答