【问题标题】:C# RSA decryptionC# RSA 解密
【发布时间】:2011-10-04 16:38:49
【问题描述】:

我已经编写了这段代码,用于使用 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);) 出现错误(“密钥不存在。”):(

【问题讨论】:

  • 如何在应用程序中设置字节数组(发送给方法的数组)?

标签: c# encryption key rsa


【解决方案1】:

RSAParameters 对象的所有其他字段呢?您未提供的私钥还有更多字段。

【讨论】:

【解决方案2】:

改变你的参数 "Key" => "key" (小写)

【讨论】:

  • 这里跟case无关;他给参数起的名字不会影响逻辑。
猜你喜欢
  • 2015-03-16
  • 2012-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-02
  • 2013-03-17
  • 1970-01-01
  • 2013-06-12
相关资源
最近更新 更多