Vue项目Rsa加密

一直做得PC端项目,都是单纯的md5加密,所以对于这一次安全性要求比较高的需要用到Rsa加密,具体步骤如下
1、安装
npm install --save jsencrypt
2、在main.js 引入
import JsEncrypt from 'jsencrypt'
Vue.prototype.jsEncrypt = JsEncrypt; 3、使用minxin封装,其中公钥和私钥,由后台提供 export default { name:'RSA-encrypt', methods:{ //加密方法 encrypt(pas){ //实例化jsEncrypt对象 let jse = new this.jsEncrypt;
//设置公钥
jse.setPublicKey('-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDU/hbv04Efj5lDd6cTJFLuaHWXszy8kmnO0skAPeWp5CqgnNdzgUjD9sc6BLUWyb+NWLxO559z2bhhb2rWLDZ9MWMdX32w3FGiG3/2FAYubNBlNLv9pXPluj6QOj9TYWtMeb/RtCbDyNXFx0zeSV3vPyZ3kH7lJEIgERvie8bMWwIDAQAB-----END PUBLIC KEY-----');
//加密
return jse.encrypt(pas);
},
//解密方法
decrypt(pas){
let jse = new this.$jsEncrypt;
jse.setPrivateKey('-----BEGIN PRIVATE KEY-----MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBANT+Fu/TgR+PmUN3pxMkUu5odZezPLySac7SyQA95ankKqCc13OBSMP2xzoEtRbJv41YvE7nn3PZuGFvatYsNn0xYx1ffbDcUaIbf/YUBi5s0GU0u/2lc+W6PpA6P1Nha0x5v9G0JsPI1cXHTN5JXe8/JneQfuUkQiARG+J7xsxbAgMBAAECgYEAzS38sImiQOIXdbvlMfZzAYGVjk62+r1cukWqJdZ60J+hRNnyXy2zCDxJjaWNQWeWZLaPqL9Ohs685PftBmbPESalWdIjADijM0HKDFS6GKEYd3CcyJPRT1joRDMnyr7GhxpngcvKTHcsxwqZdlBCjjrOe+zL9yMl3mXSKytMHEliLoTnM6F1t2WOuPk+qcc8LCVB1LV/vhVPg98tg==-----END PRIVATE KEY-----')
return jse.decrypt(pas);
}
}
}

你可能感兴趣的:(Vue项目Rsa加密)