前端如何加密解密?
安装:npm install gm-crypt
// 配置sm4参数,加密
const SM4 = require('gm-crypt').sm4;
const sm4Config = {
key: 'pwdKey',
mode: 'cbc', // ecb和cbc模式,cbc需要加iv参数
iv: 'pwdKey',
cipherType: 'base64',
};
const sm4Util = new SM4(sm4Config);
//解密
export const gmSm4Encrypt = (str)=> {
const encryptStr = sm4Util.encrypt(str);
return encryptStr;
};