{"不正确的项。\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 "";
}
求解答
– 落幕。 5年前