TypeError: The “digest” argument is required and must not be undefined

南楼画角 提交于 2019-12-21 09:22:00

问题


I am getting subject error while registering a simple Mean Application through http://localhost:3000/auth/register, that I have simply created using mean init command. pbkdf2 or crypto is generating the error and I have no idea where to look for it.

I have done lots of different things like cleared npm cache, reinstalled using npm etc. Please help me out. Following is some more information.

Mean --version: 0.12.15
npm --version: 5.0.3
node --version: v8.1.0
bower --version: 1.8.0
gulp --version: CLI and Local: 3.9.1

Code for model.UserSchema.methods.hashPassword (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\models\user.js)

/**
 * Hash password
 *
 * @param {String} password
 * @return {String}
 * @api public
 */
UserSchema.methods.hashPassword = function(password) {
  if (!password || !this.salt) return '';
  var salt = new Buffer(this.salt, 'base64');
  return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
};

Register page calls http://localhost:3000/api/register and it generates 500 Internal Server Error.

Firefox is showing following response:

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.hashPassword (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\models\user.js:165:17)
at model.<anonymous> (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\models\user.js:94:31)
at VirtualType.applySetters (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\virtualtype.js:94:25)
at model.Document.set (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:656:12)
at model._handleIndex (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:587:14)
at model.Document.set (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:547:24)
at model.Document (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\document.js:71:12)
at model.Model (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\model.js:46:12)
at new model (D:\Projects\Mean\CampaignBuilder\node_modules\mongoose\lib\model.js:3621:13)
at create (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\controllers\users.js:86:24)
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at next (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:281:22
at Function.process_params (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:335:12)
at next (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:275:10)
at loadUser (D:\Projects\Mean\CampaignBuilder\node_modules\meanio-users\server\controllers\users.js:202:24)
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:317:13)
at D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:284:7
at Function.process_params (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:335:12)
at next (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:275:10)
at D:\Projects\Mean\CampaignBuilder\node_modules\connect-modrewrite\index.js:129:7
at Layer.handle [as handle_request] (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (D:\Projects\Mean\CampaignBuilder\node_modules\meanio\lib\core_modules\server\node_modules\express\lib\router\index.js:317:13)

回答1:


Per the crypto.pbkdf2Sync method you are missing the final argument which is digest, thus the error being displayed.

crypto.pbkdf2

Also with further investigation you can see that the digest argument was required in Node v6.0.

The previous default seems to have been 'sha1'.




回答2:


This could also be caused by the wrong version of node / running a version that has calls that are not supported in the version of node that you have active

My Experience: My team has an application that requires Node 6.10.0. Sometimes I forget to switch to this version of node and run the latest code under 8.6.0 and I receive the same error. As soon as I swap back to 6.10.0 the website will allow me to login.

(I can see that the accepted answer also mentions this, but I wanted to add a more obvious answer in case it helps someone out there!)



来源:https://stackoverflow.com/questions/44606054/typeerror-the-digest-argument-is-required-and-must-not-be-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!