NodeJs Crypto error -Object has no method pbkdf2Sync

不羁的心 提交于 2020-01-10 06:07:23

问题


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


回答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?



来源:https://stackoverflow.com/questions/21165502/nodejs-crypto-error-object-has-no-method-pbkdf2sync

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