問題描述
使用 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:UsersThomasDocumentsVisual Studio 2010ProjectsModulesTestRSAForm1.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 } 導入將成功.
Is there a limit for RSA key exponents in .NET? (With Exponent == { 1, 0, 1 } the import will succeed.
問候托馬斯
推薦答案
微軟默認提供者只支持特定大小的公鑰指數,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
- 來源:http://msdn.microsoft.com/en-us/library/bb204778%28VS.85%29.aspx
這篇關于.NET 中的 RSA 密鑰指數有限制嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!