gpt4 book ai didi

javascript - 如何使用 Node.js 的加密库生成 scrypt 哈希?

转载 作者:搜寻专家 更新时间:2023-10-31 23:30:09 25 4
gpt4 key购买 nike

function sha512(s){
var sha = crypto.createHash('sha512');
sha.update(s);
return sha.digest('hex');
};
exports.sha512 = sha512;

我现在正在使用它,但我想将它切换为 scrypt。我该怎么做?

最佳答案

你应该使用 node-scrypt .

它具有清晰的 API 和良好的文档。

var scrypt = require("scrypt");
var scryptParameters = scrypt.params(0.1);

var key = new Buffer("this is a key"); //key defaults to buffer in config, so input must be a buffer

//Synchronous example that will output in hexidecimal encoding
scrypt.hash.config.outputEncoding = "hex";
var hash = scrypt.hash(key, scryptParameters); //should be wrapped in try catch, but leaving it out for brevity
console.log("Synchronous result: "+hash);

//Asynchronous example that expects key to be ascii encoded
scrypt.hash.config.keyEncoding = "ascii";
scrypt.hash("ascii encoded key", {N: 1, r:1, p:1}, function(err, result){
//result will be hex encoded
//Note how scrypt parameters was passed as a JSON object
console.log("Asynchronous result: "+result);
});

关于javascript - 如何使用 Node.js 的加密库生成 scrypt 哈希?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21804157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com