D.S*_*hah 5 javascript mocha.js node.js cryptojs
我正在尝试将 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);
};
Run Code Online (Sandbox Code Playgroud)
我尝试将摘要(“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)
Run Code Online (Sandbox Code Playgroud)
如何解决我面临的错误?
您现在可能已经解决了这个问题,但以防万一其他人也遇到这个问题 - 就像我一样:该函数的功能crypto.pbkdf2Sync(password, salt, iterations, keylen, digest)在 Node 6 中发生了变化,使摘要成为强制性的。直到节点 10,如果未提供摘要,则使用“sha1”。但 Node 10 需要它。发现这一点解决了我的问题,该死的消息与您收到的消息完全相同。
| 归档时间: |
|
| 查看次数: |
2207 次 |
| 最近记录: |