1. 安装:
npm install jsencrypt --save
2. 在项目中引入
import { JSEncrypt } from 'jsencrypt'
3. 加密
// 新建JESencrypt对象
const encryptor = new JSEncrypt()
const publicKey =
'-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnazmC6RuNrFXe/gzb8j8PZGOEw83PuIxIm8l8Sh+PBCZ2qrb6zRFHyCAveRFmislm5JeBZW14HRsIFJWepuy4NdK0ufCNbaSbKXkvmA1GXD1q/CNrLwD8W18iloxOay7TZPtWBpb8Nd9Qq1x7gAjC7D3nckOCqt/Gn6a9jOXasJSovyZ6RHrjICR0PMj8QxpnpZgTAp7s4/9BL088QbJQM79j32LXQAiHr1lK9yTgYskrDw0Czl4vA9L96lcwVFqJIA/KdV9ITE3NQf17mRhim1ny57BexBsyLIwLnxdP/nZwx6V3pO/t+39h1otq1zzjbf9DIHRus+ROE815uUgowIDAQAB-----END PUBLIC KEY-----'
// 设置公钥
encryptor.setPublicKey(publicKey) // publicKey为公钥
let username = encryptor.encrypt('xxxx') // 对username进行加密即可