在对接银行系统接口时,使用RSA进行私钥分段解密,报参数错误
public static string PrivateKeyDecrypt(string PrivateKey, string StrDecryptString)
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(PrivateKey);
byte[] encryptData = Convert.FromBase64String(StrDecryptString);
byte[] dencryContent;
if (encryptData == null || encryptData.Length <= 0)
{
throw new NotSupportedException();
}
int keySize = rsa.KeySize / 8;
byte[] buffer = new byte[keySize];
MemoryStream input = new MemoryStream(encryptData);
MemoryStream output = new MemoryStream();
while (true)
{
int readLine = input.Read(buffer, 0, keySize);
if (readLine <= 0)
{
break;
}
byte[] temp = new byte[readLine];
Array.Copy(buffer, 0, temp, 0, readLine);
byte[] decrypt = rsa.Decrypt(temp, false);
output.Write(decrypt, 0, decrypt.Length);
}
dencryContent = output.ToArray();
return Encoding.UTF8.GetString(dencryContent);
}
有什么好的办法来处理这个问题吗??