【问题标题】:Call a libsodium function with callback value调用具有回调值的 libsodium 函数
【发布时间】:2017-11-14 19:33:24
【问题描述】:

我尝试散列密码并将其存储到数据库中。 所以我使用 libsodium 和 crypto_pwhash 到一个节点应用程序中。 我创建了一个函数,导出它,但我无法收到哈希密码。

这是我的代码: 钠.js

libsodium = require('libsodium-wrappers-sumo');
 (async() => {
await libsodium.ready;
const sodium = libsodium;

module.exports.password_hash = function(password, res){
var hashed_password = [sodium.crypto_pwhash_STRBYTES];
 if (sodium.crypto_pwhash_str ( sodium.crypto_pwhash_MEMLIMIT_SENSITIVE) != 0){
   /* out of memory */
}
   return res(hashed_password);
}
/*if (sodium.crypto_pwhash_str_verify
(hashed_password, PASSWORD, strlen(PASSWORD)) != 0) {
/* wrong password */
//}
})();

app.js

sodium.password_hash("test", function(res){
        console.log(res);  
     });

错误信息是:不支持的密码输入类型。

不明白怎么回事

更新:我更新了我的代码, 现在消息错误是:定义时,输出格式必须是字符串 我认为这是数组的问题

【问题讨论】:

  • 很难理解您在sodium.js 中所做的事情,因为看起来您缺少一些括号。您可以编辑它以使其成为有效的 js 吗?
  • 我更新了我的帖子,但只剩下几行了。
  • 您需要将密码提供给应该对其进行哈希处理的函数...
  • 我更新了我的问题

标签: node.js function callback libsodium


【解决方案1】:

sodium.crypto_pwhash_str 返回哈希密码成字符串,不需要第一个参数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多