【发布时间】:2011-10-04 16:38:49
【问题描述】:
我已经编写了这段代码,用于使用 RSA 算法解密字节数组:
RSA 密钥类:
public class RsaKeys
{
#region Properties
/// <summary>
/// The modulus N.
/// </summary>
public byte[] N
{ get; set; }
/// <summary>
/// The public exponent E.
/// </summary>
public byte[] E
{ get; set; }
/// <summary>
/// The private exponent E.
/// </summary>
public byte[] D
{ get; set; }
#endregion
}
解密代码:
public static byte[] RsaDecryptByteToByte(byte[] Byte, RsaKeys Key) // TODO: test me
{
RSACryptoServiceProvider myRsa = new RSACryptoServiceProvider(2048);
RSAParameters rsaParams = new RSAParameters();
rsaParams.D = Key.D;
rsaParams.Exponent = Key.E;
rsaParams.Modulus = Key.N;
myRsa.ImportParameters(rsaParams);
return myRsa.Decrypt(Byte, false); // ERROR!!!
}
但在最后一行 (myRsa.Decrypt(Byte, false);) 出现错误(“密钥不存在。”):(
【问题讨论】:
-
如何在应用程序中设置字节数组(发送给方法的数组)?
标签: c# encryption key rsa