jsencrypt_igor

1.0.6 • Public • Published

Installing

Using npm:

$ npm install jsencrypt_igor

Example

// 公钥数据加密后向服务端发送
export const encryption = (str) => { 
  const encode = encodeURIComponent(JSON.stringify(str))
  const encrypt = new JsEncrypt()
  encrypt.setPublicKey(serverPubKey)
  const encyptRes = encrypt.encryptLong(encode)
  return btoa(encyptRes)
}
// 收到服务端数据后通过客户端私钥解密
export const decryption = (encrypted) => { 
  const decrypt = new JsEncrypt()
  decrypt.setPrivateKey(clientPriKey)
  const temp = decrypt.decryptLong(encrypted)
  return JSON.parse(decodeURIComponent(temp))
}

Readme

Keywords

none

Package Sidebar

Install

npm i jsencrypt_igor

Weekly Downloads

1

Version

1.0.6

License

ISC

Unpacked Size

180 kB

Total Files

3

Last publish

Collaborators

  • zwq1932158337