.NET中的RSA密钥指数是否有限制?
使用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}导入将成功。
关心托马斯
Microsoft的默认提供程序仅支持特定大小的公钥指数, 如CodesInChaos mused :
CNG在RSA密钥对方面更灵活。 例如,CNG支持长度大于32位的公共指数,并且它支持p和q长度不同的密钥。
和
请注意,4字节指数的限制仅适用于MS CSP。 如果使用第三方CSP,CryptoAPI应该能够使用5字节指数。
资料来源:
- http://blogs.msdn.com/b/alejacma/archive/2010/07/28/cryptoapi-and-5-bytes-exponent-public-keys.aspx
- 来源: http : //msdn.microsoft.com/en-us/library/bb204778%28VS.85%29.aspx