目录
安装 npm install gm-crypt
\src\utils\gmCrypt.js
export const pwdKey = 'testKeytestKey20'
const SM4 = require('gm-crypt').sm4
export function encrypt(pwd) {
const sm4Config = {
key: pwdKey,
mode: 'ecb',
// iv: '',
cipherType: 'base64'
}
const sm4Util = new SM4(sm4Config)
const ciphertext = sm4Util.encrypt(pwd, pwdKey)
return ciphertext
}
export function decrypt(pwd) {
const sm4Config = {
key: pwdKey,
mode: 'ecb',
// iv: '',
cipherType: 'base64'
}
const sm4Util = new SM4(sm4Config)
const plaintext = sm4Util.decrypt(pwd, pwdKey)
return plaintext
}
login.vue页面使用
import { encrypt } from '@/utils/gmCrypt'
user.password = encrypt(user.password)