C# RSA decryption

本文关键字:decryption RSA | 更新日期: 2023-09-27 18:10:29

我已经写了这个代码解密字节数组与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);)输出错误("Key does not exist."):(

C# RSA decryption

rsparameters对象的所有其他字段呢?您没有提供的私钥还有许多字段

更改参数"Key" => "Key"(小写)