C#RSA解密

时间:2011-10-04 16:38:49

标签: c# encryption key rsa

我已经使用RSA算法编写了用于解密字节数组的代码:

RSA Key类:

    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 not exists。”):(

2 个答案:

答案 0 :(得分:1)

RSAParameters对象的所有其他字段怎么样?您没有提供更多私钥的字段。

答案 1 :(得分:-3)

更改您的参数“Key”=&gt; “key”(小写)