A forked from jsencrypt and jsencrypt-ext,support for privateKey encrypt,publicKey decrypt and long plaintext.
const encrypt = new JSEncrypt()
encrypt.setPrivateKey(privateKey)
const encrypted = encrypt.encrypt("test", { by: "PrivateKey", encoding: "UTF8" })
console.log("私钥加密 encrypted:", encrypted)
const dencrypt = new JSEncrypt()
dencrypt.setPublicKey(publicKey)
const dencrypted = dencrypt.decrypt(encrypted as string, { by: "PublicKey" })
console.log("公钥解密 dencrypted:", dencrypted)
function(args) | options: IEncryptEncodingOptions = { encoding?: "ASCII" |"UTF8"; by?: "PrivateKey" |"PublicKey"; } |
desc |
---|---|---|
encrypt(str, options) | default = { encoding: "UTF8", by: "PublicKey" } | 公钥(d)/私钥 加密 |
decrypt(str, options) | default = { by: "PrivateKey" } | 私钥(d)/公钥 解密 |
const encrypt = new JSEncrypt()
encrypt.setPublicKey(publicKey)
const longMessage = JSON.stringify(
Array.from(new Array(100))
.fill("壹贰叁肆伍陆柒捌玖拾佰仟")
.map((i, index) => ({ name: `${index}${i}` }))
)
const encrypted = encrypt.encryptExt(longMessage)
console.log("公钥加密 encrypted:", encrypted)
const dencrypt = new JSEncrypt()
dencrypt.setPrivateKey(privateKey)
const dencrypted = dencrypt.decryptExt(encrypted as string)
console.log("私钥解密 dencrypted:", dencrypted)
function(args) | options: IEncryptEncodingOptions = { encoding?: "ASCII" |"UTF8"; by?: "PrivateKey" |"PublicKey"; } |
description |
---|---|---|
encryptOxr(str, options) | default = { encoding: "UTF8", by: "PublicKey" } | 公钥(d)/私钥 加密 |
decryptOxr(str, options) | default = { by: "PrivateKey" } | 私钥(d)/公钥 解密 |