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ryPry4iTtsoNgkTfmcYE+K3hazTeWDnRVRjiAex7ujQ==`;
// 创建加密对象实例
var encryptor = new JSEncrypt();
//设置公钥
encryptor.setPublicKey(pubKey);
// 对内容进行加密
var rsaPassWord = encryptor.encrypt('需加密的内容....');
console.log('加密后:', rsaPassWord);
// 解密
//创建解密对象实例
var decrypt = new JSEncrypt();
//设置秘钥
decrypt.setPrivateKey(priKey);
//解密之前拿公钥加密的内容
var uncrypted = decrypt.decrypt(rsaPassWord);
console.log('解密后:', uncrypted);
JSEncrypt之RSA加密详解
最新推荐文章于 2024-07-09 10:43:10 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)