0

I want to use pbkdf2Sync method to encrypt password. My nodejs version is 0.12.7. By default, there should be crypto module with pbkdf2Sync method or randomBytes, but occurs TypeError: Object # has no method 'pbkdf2Sync'. I have tried also npm install crypto, but it doesn't help. It looks like crypto module doesn't exist.

Snippet code of my User model:

var crypto = require('crypto');
UserSchema.methods.setPassword = function (password) {
this.salt = crypto.randomBytes(16).toString('hex');
this.hash = crypto.pbkdf2Sync(password, this.salt, 1000, 64).toString('hex');
};

Solutions from similar topic don't work.

Community
  • 1
  • 1
Meliasz
  • 1
  • 1
  • 1
  • Why do you think that it *looks like [the] crypto module doesn't exist*? `randomBytes` seems to work fine, so that sounds really unlikely. Also, from the question, you seem to be severely confused what module you actually want to use; do you want `crypto` from npm or from the node standard library? As a final note, can you reproduce the problem with a [self-contained example](http://sscce.org/)? [This code](http://pastebin.com/gk8t2EKR) works fine for me. – phihag Jul 19 '15 at 10:16
  • If you've done `npm install crypto`, go ahead and remove it to possibly avoid any confusion. You definitely want the built-in `crypto` module instead. – mscdex Jul 19 '15 at 11:20

0 Answers0