npm install jsencrypt --save
二、引入jsencrypt
// 1、全局引入在 main.js 文件中
import JSEncrypt from "jsencrypt";
Vue.prototype.jsEncrypt = JSEncrypt;
// 2、局部引入,在需要使用RSA加密的文件中
import JSEncrypt from 'jsencrypt'
三、使用步骤
1、先调用接口获取公钥
getRsa().then(res=>{
this.public_key = res.data.data;
})
2、对要加密的内容做加密处理
encryptRsa() {
let encrypt = new JSEncrypt();
encrypt.setPublicKey(this.public_key);
return encrypt.encrypt(md5(md5(this.password)));
},
3、最后一步,加密内容传给后端