NodeJs加密错误-Object没有方法pbkdf2Sync [英] NodeJs Crypto error -Object has no method pbkdf2Sync

查看:183
本文介绍了NodeJs加密错误-Object没有方法pbkdf2Sync的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using nodeJS Crypto Module to encrypt password.

示例代码

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

但是我不确定,每当我打电话给这个方法,都会出现以下错误:

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

TypeError:Object#没有方法'pbkdf2Sync'

请让我知道什么问题

感谢所有

推荐答案

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

pbkdf2Sync was added to the Crypto module in version 0.9.3.

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

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?

这篇关于NodeJs加密错误-Object没有方法pbkdf2Sync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆