public string Decrypt()
{
var base64EncryptedData = "";
string privateKey = @"<RSAKeyValue>....</RSAKeyValue>";
RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
provider.FromXmlString(privateKey);
// 解密数据
var r = string.Empty;
byte[] src = Convert.FromBase64String(base64EncryptedData);
List<byte> dest = new List<byte>();
int KEY_SIZE = provider.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 = provider.Decrypt(t, false);//分段解密
i += KEY_SIZE;
dest.AddRange(t1);
}
}
else //小于等于128字节
{
dest.AddRange(provider.Decrypt(src, false));
}
r = System.Text.Encoding.UTF8.GetString(dest.ToArray());
return r;
}