首页新闻找找看学习计划

C# RSA 证书解密

0
悬赏园豆:5 [待解决问题]

{"不正确的项。\r\n"}

try
{
string path = HttpContext.Current.Server.MapPath("~/");
string cert = "D:\800010000020019.pfx";
//SHA256WithRSA
X509Certificate2 _X509Certificate2 = new X509Certificate2(cert, password);
using (RSACryptoServiceProvider RSACryptography = _X509Certificate2.PrivateKey as RSACryptoServiceProvider)
{
Byte[] CiphertextData = Convert.FromBase64String(ciphertext);
int MaxBlockSize = RSACryptography.KeySize / 8; //解密块最大长度限制
if (CiphertextData.Length <= MaxBlockSize)
return Encoding.UTF8.GetString(RSACryptography.Decrypt(CiphertextData, false));
using (MemoryStream CrypStream = new MemoryStream(CiphertextData))
using (MemoryStream PlaiStream = new MemoryStream())
{
Byte[] Buffer = new Byte[MaxBlockSize];
int BlockSize = CrypStream.Read(Buffer, 0, MaxBlockSize);
while (BlockSize > 0)
{
Byte[] ToDecrypt = new Byte[BlockSize];
Array.Copy(Buffer, 0, ToDecrypt, 0, BlockSize);
Byte[] Plaintext = RSACryptography.Decrypt(ToDecrypt, false);
PlaiStream.Write(Plaintext, 0, Plaintext.Length);
BlockSize = CrypStream.Read(Buffer, 0, MaxBlockSize);
}

                    return Encoding.UTF8.GetString(PlaiStream.ToArray());
                }
            }
        }
        catch (Exception ex)
        {
            return "";
        }
落幕。的主页 落幕。 | 初学一级 | 园豆:2
提问于:2018-11-28 14:29

求解答

落幕。 1年前
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册