jsencrypt_igor
v1.0.6
Published
for long text size encryption and decryption
Downloads
6
Readme
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))
}