jsencrypt
jsencrypt copied to clipboard
bug for the string when it's too long
trafficstars
hello Author. It had a problem that the string when it's too long , the decrypt funtion is return "null". how can i solve this problem?
same problem, please help
i think i found an answer at http://security.stackexchange.com/a/33445
Not a bug close this
https://github.com/lsqswl/rsaencrypt
You can try the following code 你可以尝试以下代码,通过分块加密
/**
* 分段加密长字符串
* @param {string} str the string to encrypt
* @return {string} the encrypted string encoded in base64
* @public
*/
encryptLong: function(str,$key) {
var encryptor = new JSEncrypt();
encryptor.setPublicKey($key);
var maxChunkLength = 100,
output = '',
inOffset = 0,
outOffset = 0;
while (inOffset < str.length) {
console.log(str.substring(inOffset, inOffset + maxChunkLength));
output += encryptor.encrypt(str.substring(inOffset, inOffset + maxChunkLength));
inOffset += maxChunkLength;
}
return output;
},
/**
* 长文本解密
* @param {string} string 加密后的base64编码
* @returns {string} 解密后的原文
*/
decryptLong: function(string,$key) {
var decryptor = new JSEncrypt();
decryptor.setPrivateKey($key);
var maxChunkLength = 172,
output = '',
inOffset = 0,
outOffset = 0;
while (inOffset < string.length) {
console.log(string.substring(inOffset, inOffset + maxChunkLength));
output += decryptor.decrypt(string.substring(inOffset, inOffset + maxChunkLength));
inOffset += maxChunkLength;
}
return output;
},
您好!您的来信已收到,谢谢!