TIM*_*MEX 3 javascript hash cryptography node.js
function sha512(s){
var sha = crypto.createHash('sha512');
sha.update(s);
return sha.digest('hex');
};
exports.sha512 = sha512;
Run Code Online (Sandbox Code Playgroud)
我现在正在使用它,但我想将它切换为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);
});
Run Code Online (Sandbox Code Playgroud)