哈希算法签名:(MD5或SHA1、sha256、sha512)
const crypto = require('crypto');
let hash = crypto.createHash('md5'); //创建hash对象
// 可任意多次调用update();
hash.update('abcd'); //添加数据
hash.update('efg'); //添加数据
console.log(hash.digest('hex')); //7ac66c0f148de9519b8bd264312c4d64
Hmac哈希算法签名:(不同的是,Hmac还需要一个密钥)
const crypto = require('crypto');
let hmac = crypto.createHmac('sha256', '我是密匙字符串');
hmac.update('abcd'); //添加数据
hmac.update('efg'); //添加数据
console.log(hmac.digest('hex'));
//4132f9ccff8720f858a1a161f833e73e0f5440741a2e28eab1d2cd5a217a1cff
数据的加密和解密:(Cipher加密、Decipher解密)