.NET中的RSA密钥指数是否有限制? [英] Is there a limit for RSA key exponents in .NET?

查看:187
本文介绍了.NET中的RSA密钥指数是否有限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using C# I cannot import a public RSA key with an exponent of {1, 0, 0, 0, 15}: There is an exception:

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

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

Is there a limit for RSA key exponents in .NET? (With Exponent == { 1, 0, 1 } the import will succeed.

关于
Thomas

Regards Thomas

推荐答案

Microsoft的默认提供程序仅支持特定大小的公共密钥指数,随着CodesInChaos的沉思

The default provider by Microsoft only supports public key exponents of a specific size, as CodesInChaos mused:


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

CNG is more flexible with regard to RSA key pairs. For example, CNG supports public exponents larger than 32-bits in length, and it supports keys in which p and q are different lengths.


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

Please, note that the restriction of 4 byte exponents are for MS CSPs only. CryptoAPI should be able to work with 5 byte exponents if using a third-party CSP.

来源:

  • http://blogs.msdn.com/b/alejacma/archive/2010/07/28/cryptoapi-and-5-bytes-exponent-public-keys.aspx
  • source of source: http://msdn.microsoft.com/en-us/library/bb204778%28VS.85%29.aspx

这篇关于.NET中的RSA密钥指数是否有限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆