js 加密算法
(1)md5摘要算法
npm install crypto-js
const CryptoJS = require('crypto-js');
//原始数据
const data = '123456';
//生成MD5摘要
const md5Digest = CryptoJS.MD5(data).toString();
console.log(md5Digest);
(2)AES加密
const CryptoJS = require("crypto-js")
//密钥(128位,16字节)
var key = CryptoJS.enc.Utf8.parse('0123456789abcdef');
//初始化向量(IV)(128位,16字节)
var iv = CryptoJS.enc.Utf8.parse('1234567890abcdef');
//待加密的数据
var plaintext = 'Hello, qiao!';
//进行AES-128加密,使用CBC模式和PKCS7填充
var encrypted = CryptoJS.AES.encrypt(plaintext, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
//获取加密后的密文
var ciphertext = encrypted.toString();
console.log(ciphertext);