NodeJs加密错误-Object没有方法pbkdf2Sync

时间:2022-07-16 18:27:34

I am using nodeJS Crypto Module to encrypt password.

我使用nodeJS加密模块来加密密码。

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'

TypeError:Object#没有方法'pbkdf2Sync'

Please let me know what is the issues

请告诉我这是什么问题

Thanks all

1 个解决方案

#1


1  

pbkdf2Sync was added to the Crypto module in version 0.9.3.

pbkdf2Sync已添加到版本0.9.3中的Crypto模块。

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.

您可以将Node的安装升级到0.9.3或更高版本,也可以使用函数的异步版本crypto.pbkdf2,这需要回调。

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?

这只是一个例子;对同步与异步操作的完整讨论大大超出了本问题的范围。对该主题的一个很好的概述是如何从异步调用返回响应?

#1


1  

pbkdf2Sync was added to the Crypto module in version 0.9.3.

pbkdf2Sync已添加到版本0.9.3中的Crypto模块。

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.

您可以将Node的安装升级到0.9.3或更高版本,也可以使用函数的异步版本crypto.pbkdf2,这需要回调。

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?

这只是一个例子;对同步与异步操作的完整讨论大大超出了本问题的范围。对该主题的一个很好的概述是如何从异步调用返回响应?