我已經所著此代碼爲解密的字節數組與RSA算法:C#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);)出現錯誤(「密鑰不存在」):(
如何在應用程序中設置字節數組(您發送給方法的字節數組)? –