I have writed this code for decrypt a byte array with the RSA algorithm:
the RSA Key class:
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
}
the code for the decryption:
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!!!
}
but in the last line (myRsa.Decrypt(Byte, false);) comes out an error ( "Key does not exist.") :(
What about all the other fields of the RSAParameters object? There are many more fields for a private key that you are not providing.
change your param "Key" => "key" (lowercase)
精彩评论