Answers for "how to hash with crypto Node.js"

0

how to hash with crypto Node.js

//Hash something.
crypto = crypto || require('crypto');
const createHash = crypto.createHash;
function sha1(txt) {
	return createHash('sha1') // <-- You can use other than sha1
  		.update(txt) //set what to encode
  		.digest('hex') //basically another way to encode. hex is base16 so for example doing .digest('base64') encodes 4x more effenciently
}
const hash = sha1('password');
hash == sha1('password')?'yes':'no'; //yes
Posted by: Guest on July-23-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language