📜  如何使用加密 Node.js 进行散列 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:40.407000             🧑  作者: Mango

代码示例1
//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