前端使用JSEncrypt进行加密和解密

下载链接:https://www.bootcdn.cn/jsencrypt/

使用方法:

1、引入jsencrypt

2、使用方法

// 加密公钥
const key = `xxxxxx`;
function setEncrypt (msg) {
  //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

最后小声哔哔一点:不知道为什么csdn上的人随便一个小问题都要积分都要钱,就比如这个Js的下载

  

posted @ 2022-09-26 17:45  锦年与panda  Views(951)  Comments(0Edit  收藏  举报