1 使用JSEncrypt加密解密
// 安装 npm install jsencrypt
import { JSEncrypt } from 'jsencrypt'
// 加密公钥
const key = `----`
// 加密
export function encrypt (msg) {
const encryption = new JSEncrypt()
encryption.setPublicKey(key)
return encryption.encrypt(msg)
}
// 解密私钥
const privateKey = `---`
// 解密
export function decrypt (msg) {
let decryption = new JSEncrypt()
decryption.setPrivateKey(privateKey)
return decryption.decrypt(msg)
}
2