rsa对证书的加密和解密
hytwl 2010-08-06 10:56:15 为什么我用RSA算法用公钥对文件进行加密,在解密时,只能由自己进行解密,用另外一个私钥进行解密时,就报
不正确的数据。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Security.Cryptography.CryptographicException: 不正确的数据。
源错误:
行 100: if (blocksize == k)
行 101: {
行 102: encryblock = oRSA1.Decrypt(buffer, false);
行 103: fs.Write(encryblock, 0, encryblock.Length);
行 104: }
源文件: d:\EncryptedSystem\EncryptedSystem\Default.aspx.cs 行: 102
堆栈跟踪:
[CryptographicException: 不正确的数据。
]
System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr) +33
System.Security.Cryptography.Utils._DecryptKey(SafeKeyHandle hPubKey, Byte[] key, Int32 dwFlags) +0
System.Security.Cryptography.RSACryptoServiceProvider.Decrypt(Byte[] rgb, Boolean fOAEP) +264
_Default.Decrypt(String FilePath, String OutFile) in d:\EncryptedSystem\EncryptedSystem\Default.aspx.cs:102
_Default.Button2_Click(Object sender, EventArgs e) in d:\EncryptedSystem\EncryptedSystem\Default.aspx.cs:260
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5087
这个错误 就是说encryblock = oRSA1.Decrypt(buffer, false);解密时发生错误。