解密时出错-RSA解密 [英] Error while decrypting - RSA decryption
本文介绍了解密时出错-RSA解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够成功加密,但是无法解密.
我的代码是这样的:
I am able to encrypt successfully but am unable to decrypt it.
My code goes like this:
public string DecryptRSA(string data, string privatestring)
{
string rsaprivate = System.Web.HttpContext.Current.Server.MapPath(privatestring);
string clearData = null;
// try
// {
CspParameters param = new CspParameters();
param.Flags = CspProviderFlags.UseMachineKeyStore;
RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(param);
//string merchantRsaPublic = GetXmlRsaKey(rsaprivate);
StreamReader reader = new StreamReader(rsaprivate);
string privatekeyXml = reader.ReadToEnd();
rsaProvider.FromXmlString(privatekeyXml);
byte[] asciiString = Encoding.ASCII.GetBytes(data);
#1 byte[] decryptedData = rsaProvider.Decrypt(asciiString, true);
string resultString = Convert.ToBase64String(decryptedData);
// clearData = Convert.ToString(decryptedData);
// }
//catch (CryptographicException ex)
// {
Console.Write("asasa");
//Log.Error("A cryptographic error occured trying to decrypt a value for " + privatestring, ex);
//}
return resultString;
}
现在,有了try catch块,就没有运行时错误,并且也收到了所需的输出.
但是,使用调试和No try catch block第1行给出了错误消息:
要解密的数据超过了此模数256字节的最大值." ->我对此有所了解,但不知道如何解决此错误.什么是正确的代码?
请帮忙.
Now, with the try catch block there is no runtime error and the desired ouput is also received.
However with debugging & no try catch block the line #1 gives a error which says:
"The data to be decrypted exceeds the maximum for this modulus of 256 bytes."-> I have knowledge about this but don''t know, how to solve this error. What would be the right code?
Please help.
推荐答案
看看这些讨论,它们看起来很相似:
链接1 [链接2 [
Have a look at these discussions, they look similar:
Link 1[^]
Link 2[^]
Error reported has been faced by quite a lot of people. Google for more, if needed.
这篇关于解密时出错-RSA解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文