vue项目中使用RSA加密
1.按装依赖
npm install jsencrypt --save
2.main.js中引用依赖
// main.js 中 import JSEncrypt from 'jsencrypt'; Vue.prototype.$getRsaCode = function(str){ // 注册方法 let pubKey = `-----BEGIN PUBLIC KEY----- rerwrwewewewewesssaczdscasdafffvzdxdas-----END PUBLIC KEY-----`;// ES6 模板字符串 引用 rsa 公钥 let encryptStr = new JSEncrypt(); encryptStr.setPublicKey(pubKey); // 设置 加密公钥 let data = encryptStr.encrypt(str.toString()); // 进行加密 return data; }
3.在login.vue中使用加密
loginIn(){
let rasPw = this.$getRsaCode(this.loginForm.password); // ras 加密 密码
}