我正在尝试将crypto.pbkdf2添加到我的系统中,并且在使用Mocha测试各种功能时,我不断返回摘要问题。我的哈希方法代码是:
Account.prototype.hashPassword = function (password, salt, callback) {
// we use pbkdf2 to hash and iterate 10k times by default
var iterations = 10000,
keylen = 64; //64 bit.
this.crypto.pbkdf2(password, salt, iterations, keylen,'sha1', callback);
};
我尝试将摘要('sha1')更改为许多内容,包括'shah256','null'或摘要。但是我的测试仍然失败,并显示以下错误:
TypeError [ERR_INVALID_ARG_TYPE]: The "digest" argument must be one of type string or null. Received type undefined
at check (internal/crypto/pbkdf2.js:56:13)
at Object.pbkdf2Sync (internal/crypto/pbkdf2.js:45:5)
at UserMock.seedUsers (test\user-mock.js:32:39)
at Context.<anonymous> (test\account-test.js:296:27)
如何解决遇到的错误?
答案 0 :(得分:0)
您现在可能已经解决了这个问题,但是以防万一其他人也遇到了这个问题-就像我一样:
在节点6中,功能crypto.pbkdf2Sync(password, salt, iterations, keylen, digest)
的功能已更改,以强制 摘要 。直到节点10,如果未提供 digest ,则使用'sha1'。但是节点10需要它。
发现这一点后,我的想法和我得到的信息完全一样。