解决办法就是分小块解密,网上多有提出这个办法的,但我还是把部分代码列出来吧。
string base64String = "";//待解密的base64字符串
byte[] src = Convert.FromBase64String(base64String);
List<byte> dest = new List<byte>();
int KEY_SIZE = rsp.KeySize / 8;//128 rsp -> System.Security.Cryptography.RSACryptoServiceProvider
if (src.Length > KEY_SIZE) //要解密的数据超过此模块的最大值 128 字节
{
int i = 0;
while (i < src.Length)
{
byte[] t = null;
if (i + KEY_SIZE > src.Length) //不是128的整数倍
{
t = new byte[src.Length - i];
}
else //128的整数倍
{
t = new byte[KEY_SIZE];
}
Array.Copy(src, i, t, 0, t.Length);
byte[] t1 = rsp.Decrypt(t, false);//分段解密
i += KEY_SIZE;
dest.AddRange(t1);
}
}
else //小于等于128字节
{
dest.AddRange(rsp.Decrypt(src, false));
}
Console.WriteLine("---->" + System.Text.Encoding.UTF8.GetString(dest.ToArray()));