本文介绍了.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
RegardsThomas
推荐答案
Microsoft的默认提供程序仅支持特定大小的公共密钥指数,:
The default provider by Microsoft only supports public key exponents of a specific size, as CodesInChaos mused:
和
来源:
- 源代码:
- 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密钥指数是否有限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!