我曾经在登录和注册功能中使用以下代码:
var crypto = require('crypto');
... ...
this.hash = crypto.pbkdf2Sync(password, this.salt, 1000, 64).toString('hex');
我已经注册了用户。
昨天,我更新了npm,现在显示错误:
events.js:182
throw er; // Unhandled 'error' event
^
TypeError: The "digest" argument is required and must not be undefined
at pbkdf2 (crypto.js:635:11)
at Object.exports.pbkdf2Sync (crypto.js:628:10)
at model.UserSchema.methods.validPassword (/opt/myapp/models/Users.js:35:23)
at /opt/myapp/config/passport.js:16:23
at model.Query.<anonymous> (/opt/myapp/node_modules/mongoose/lib/model.js:3745:16)
at /opt/myapp/node_modules/kareem/index.js:277:21
at /opt/myapp/node_modules/kareem/index.js:131:16
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
所以有人知道我应该向digest
提供crypto.pbkdf2Sync
论证吗?我希望注册用户/密码仍然有效。
答案 0 :(得分:1)
来自crypto.pbkdf2Sync
的node.js文档:
const crypto = require('crypto');
const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 512, 'sha512');
console.log(key.toString('hex')); // '3745e48...aa39b34'
您还需要指定编码算法sha512
这是digest parameter
,请参阅文档中的最后一个参数。