我尝试将密码散列并存储到数据库中。因此,我在node应用程序中使用了带有crypto_pwhash的libsodium。我创建了一个函数,将其导出,但我无法收到散列密码。
下面是我的代码: sodium.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);
});
错误消息是:密码输入类型不受支持。
我不明白出了什么问题
更新:我更新了我的代码,现在错误消息是:当定义时,输出格式必须是一个字符串,我认为这是数组的问题
发布于 2017-11-20 12:54:43
sodium.crypto_pwhash_str将散列密码返回到字符串中,不需要第一个参数
https://stackoverflow.com/questions/47293862
复制相似问题