繁体   English   中英

如何修复Node.js上的crypto.pbkdf2错误

[英]How to fix crypto.pbkdf2 error on node.js

我试图将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)

如何解决我面临的错误?

您可能现在已经解决了这个问题,但是以防万一其他人也遇到了这个问题-就像我所做的那样:在节点6中更改了crypto.pbkdf2Sync(password, salt, iterations, keylen, digest)函数的功能,使其必须强制进行摘要 直到节点10,如果未提供摘要 ,则使用“ sha1”。 但是节点10需要它。 发现这一点后,我的想法和我得到的信息完全一样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM