什么是RSA?
RSA加密算法是最常用的非对称加密算法,它既能用于加密,也能用于数字签名。
在vue中使用加密
1.首先引入jsencrypt
npm install jsencrypt --save
2.复制代码在main.js中引入
import JsEncrypt from 'jsencrypt'
Vue.prototype.$jsEncrypt = JsEncrypt
3.复制代码将加密解密方法封装到通用的js内
let publicKey = '这里是封装的公钥'
let privateKey = '这里是封装的私钥'
//加密方法
RSAencrypt(pas){
//实例化jsEncrypt对象
let jse = new JSEncrypt();
//设置公钥
jse.setPublicKey(publicKey);
// console.log('加密:'+jse.encrypt(pas))
return jse.encrypt(pas);
},
//解密方法
RSAdecrypt(pas){
let jse = new JSEncrypt();
// 私钥
jse.setPrivateKey(privateKey)
// console.log('解密:'+jse.decrypt(pas))
return jse.decrypt(pas);
},