【问题标题】:Is there a limit for RSA key exponents in .NET?.NET 中的 RSA 密钥指数有限制吗?
【发布时间】:2014-12-14 21:51:09
【问题描述】:

使用 C# 我无法导入指数为 {1, 0, 0, 0, 15} 的公共 RSA 密钥:有一个例外:

System.Security.Cryptography.CryptographicException was caught
  HResult=-2146893819
  Message=Bad Data.

  Source=mscorlib
  StackTrace:
       at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
       at System.Security.Cryptography.Utils._ImportKey(SafeProvHandle hCSP, Int32 keyNumber, CspProviderFlags flags, Object cspObject, SafeKeyHandle& hKey)
       at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters(RSAParameters parameters)
       at TestRSA.Form1.buttonTest_Click(Object sender, EventArgs e) in c:\Users\Thomas\Documents\Visual Studio 2010\Projects\Modules\TestRSA\Form1.cs:line 32

使用代码:

RSACryptoServiceProvider rsaAlg = new RSACryptoServiceProvider();
RSAParameters key = new RSAParameters();
key.Exponent = new byte[5] { 1, 0, 0, 0, 15 };
key.Modulus = GetModulus(); // byte Array with length 256...
rsaAlg.ImportParameters(key); // <<== this call will throw the exception

.NET 中的 RSA 密钥指数有限制吗? (使用 Exponent == { 1, 0, 1 } 导入将成功。

问候 托马斯

【问题讨论】:

  • 一些 RSA 实现将公共指数限制为 32 位。你的例子有 33 个。所以我猜微软的实现有这个限制。

标签: c# cryptography rsa exponent system.security


【解决方案1】:

Microsoft 的默认提供程序仅支持特定大小的公钥指数as CodesInChaos mused

CNG 在 RSA 密钥对方面更加灵活。例如,CNG 支持长度大于 32 位的公共指数,并且支持 p 和 q 长度不同的密钥。

请注意,4 字节指数的限制仅适用于 MS CSP。如果使用第三方 CSP,CryptoAPI 应该能够使用 5 字节指数。

来源:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 2012-03-25
    • 2014-01-14
    • 2012-01-10
    • 1970-01-01
    相关资源
    最近更新 更多