Vue-使用**JSEncrypt**给证件号手机号加密解密

一。使用JSEncrypt给证件号手机号加密解密

1.vue项目首先通过npm insatll jsencrypt –save 下载下来

2.在需要的组件引入次模块 import JSEncrypt from ‘jsencrypt’

  // 加密公钥

​    const key = `----`



​    // 加密

​    export function setEncrypt(msg) {

​      const jsencrypt = new JSEncrypt()

​      jsencrypt.setPublicKey(key)

​      return jsencrypt.encrypt(msg)

​    }

//现在main.js中将函数挂载到Vue原型上面
Vue.prototype.setEncrypt = function(msg){
    const jsencrypt = new JSEncrypt()

​      jsencrypt.setPublicKey(key)

​      return jsencrypt.encrypt(msg)
}

​    // 解密私钥

​    const privateKey = `---`



​    // 解密

​    export function decrypt(msg) {

​      let decrypt = new JSEncrypt()

​      decrypt.setPrivateKey(privateKey)

​      var decryptMsg = decrypt.decrypt(msg)

​      return decryptMsg

​    }
//现在main.js中将函数挂载到Vue原型上面
Vue.prototype.decrypt = function(msg){
    let decrypt = new JSEncrypt()
​      decrypt.setPrivateKey(privateKey)
​      return decrypt.decrypt(msg)
}