Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将160位散列为固定的整数?_Javascript_Node.js_Hash_Hmac - Fatal编程技术网

Javascript 将160位散列为固定的整数?

Javascript 将160位散列为固定的整数?,javascript,node.js,hash,hmac,Javascript,Node.js,Hash,Hmac,我想将密钥散列消息身份验证码(HMAC)的输出散列为固定数量的整数(10-12位)。最佳节点JS可能就是您想要的 您应该能够像这样散列它: var bcrypt = require('bcrypt'); const saltRounds = 10; const myPlaintextPassword = 's0/\/\P4$$w0rD'; const someOtherPlaintextPassword = 'not_bacon'; 另一个是,你可以这样做: 同步的 异步的 示例代码取自提供的

我想将密钥散列消息身份验证码(HMAC)的输出散列为固定数量的整数(10-12位)。最佳节点JS可能就是您想要的

您应该能够像这样散列它:

var bcrypt = require('bcrypt');
const saltRounds = 10;
const myPlaintextPassword = 's0/\/\P4$$w0rD';
const someOtherPlaintextPassword = 'not_bacon';
另一个是,你可以这样做:

同步的 异步的
示例代码取自提供的源代码。

谢谢@Jai,我对这一点不太熟悉。您能告诉我bcrypt.hashSync(“bacon”)的输出是什么吗;它是一个数字,160位信息的长度是多少
var hash = bcrypt.hashSync("bacon");

bcrypt.compareSync("bacon", hash); // true
bcrypt.compareSync("veggies", hash); // false
bcrypt.hash("bacon", null, null, function(err, hash) {
    // Store hash in your password DB.
});