0

I am using nodeJS Crypto Module to encrypt password.

Sample code:

crypto.pbkdf2Sync(password, salt, 200, 64).toString('base64');

But I am not sure, whenever I call this method, following error shown

TypeError: Object # has no method 'pbkdf2Sync'

Please let me know what is the issues

Thanks all

gevorg
  • 4,835
  • 4
  • 35
  • 52
niran
  • 1,920
  • 8
  • 34
  • 60
  • Sounds like your `crypto` object doesn't have a `pbkdf2Sync` method. Maybe your node version is less than `0.9.3`, which is when that method was added to the `crypto` module? (Compare: [`0.9.2`](http://nodejs.org/docs/v0.9.2/api/crypto.html) vs. [`0.9.3`](http://nodejs.org/docs/v0.9.3/api/crypto.html).) – apsillers Jan 16 '14 at 15:18
  • ya that method is not there. this the version i am using. $ node - v 0.8.15 – niran Jan 16 '14 at 15:30

1 Answers1

1

pbkdf2Sync was added to the Crypto module in version 0.9.3.

You can either upgrade your installation of Node to 0.9.3 or higher, or you can use the asynchronous version of the function, crypto.pbkdf2, which requires a callback.

If your previous code looked like

var result = crypto.pbkdf2Sync(password, salt, 200, 64);
var encodedResult = result.toString('base64');
doStuff(encodedResult);

Then the asynchronous code might look like:

crypto.pbkdf2Sync(password, salt, 200, 64, function(err, result) {
    var encodedResult = result.toString('base64');
    doStuff(encodedResult);
});

This is merely an example; a full discussion of sychronous versus asynchronous operations is vastly outside the scope of this question. One good overview of the topic is How do I return the response from an asynchronous call?

Community
  • 1
  • 1
apsillers
  • 112,806
  • 17
  • 235
  • 239