crypto模块 是 Node.js 内置的密码模块,封装了一些密码处理方法。 crypto 摘要算法的使用方法,几乎跟 Python 的  hashlib模块 是一样的,参考 - 摘要算法。
const crypto = require('crypto')
hash = crypto.createHash('md5') // md5
hash.update('date')
console.log(hash.digest('hex')) // 5fc732311905cb27e82d67f4f6511f7f
// 增强
hash = crypto.createHash('sha1') // sha1
hash.update('date')
console.log(hash.digest('hex')) // e927d0677c77241b707442314346326278051dd6
// 越强越安全,执行效率越低
// sha256 
// sha512
// ...hmac 算法
/* 
  hmac 算法,增强版的摘要算法,需要密钥
  密钥,通常的也叫做 “盐”
*/
hmacsha256 = crypto.createHmac('sha256', 'secret-key')
hmacsha256.update('data')
hmacsha256.update('append data')
hmacsha256.digest('hex'))
// 对应还有 hmacmd5 128、hmacsha1 160 ... 对称加密是一种双向加密算法,跟摘要算法的单向加密不同,它是支持加解密的,通过配备一个 密钥 完成。AES 是对称加密的一种,常见算法有 aes192、aes-128-ecb、aes-256-cbc。
const crypto = require('crypto')
// 加密
function aesEncrypt(data, key) {
  let cipher = crypto.createCipher('aes192', key)
  let crypted = cipher.update(data, 'utf8', 'hex')
  return cipher.final('hex')
}
// 解码
function aesDecrypt(encrypt, key) {
  let decipher = crypto.createDecipher('aes192', key);
  let decrypted = decipher.update(encrypt, 'hex', 'utf8');
  return decipher.final('utf8');
}
let encrypt = aesEncrypt('data','key') // 加密
console.log(encrypt) // 998118c1207f9e6fa5ee610c5bfd8ef0
let data = aesDecrypt(encrypt, 'key') // 解密
console.log(data) // data