在vue中使用国密SM4

https://blog.csdn.net/weixin_41164499/article/details/125390384

npm install gm-crypt
const SM4 = require(‘gm-crypt’).sm4

let sm4Config = {
key: ‘sk7&*~I%R4^a$sxz’,
mode: ‘ecb’, // 加密的方式有两种,ecb和cbc两种,也是看后端如何定义的,不过要是cbc的话下面还要加一个iv的参数,ecb不用
// optional: this is the cipher data’s type; Can be ‘base64’ or ‘text’
cipherType: ‘base64’ // default is base64

}
let sm4 = new SM4(sm4Config)

export default sm4

import sm4 from "@/lib/sm4”

let Account = sm4.encrypt(“12345”); //账号加密
let Account1 = sm4.decrypt(“12345”); //账号解密

console.log(Account1,‘Account’)

你可能感兴趣的:(vue.js,javascript,前端)