使用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
}

  

原文地址:https://www.cnblogs.com/hlweng-0207/p/12971180.html