开发者

C# RSA decryption

开发者 https://www.devze.com 2023-04-11 05:20 出处:网络
I have writed this code for decrypt a byte array with the RSA algorithm: the RSA Key class: public class RsaKeys

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号