简体   繁体   中英

C# RSA decryption

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.

更改您的参数“ Key” =>“ key”(小写)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM