-
安装插件jsencrypt
npm install jsencrypt
-
导入
import JSEncrypt from 'jsencrypt'
-
使用
utils/index.js
// 封装RSA加密方法
export function encryptedData(data) {
// 新建JSEncrypt对象
const encryptor = new JSEncrypt(undefined)
// 设置公钥
const publicKey = '公钥'
encryptor.setPublicKey(publicKey)
// 加密数据
return encryptor.encrypt(data)
}
login.vue
// 引入加密方法
import { encryptedData } from '@/utils'
// 加密用户名
const userNameKey = encryptedData('zs')
// 加密密码
const passwordKey = encryptedData('123456')