使用JSEncrypt加密解密

import { JSEncrypt } from 'jsencrypt'

// 加密公钥
const key = `----`

// 加密
export function setEncrypt (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
}

  

posted @ 2020-05-27 10:50  小小李的世界  阅读(27209)  评论(0编辑  收藏  举报