2

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 } の場合、インポートは成功します。

よろしくトーマス

4

1 に答える 1

3

CodesInChaos mused として、Microsoft による既定のプロバイダーは、特定のサイズの公開キー指数のみをサポートします。

CNG は、RSA キー ペアに関してより柔軟です。たとえば、CNG は長さが 32 ビットを超える公開指数をサポートし、p と q の長さが異なるキーをサポートします。

4 バイト指数の制限は MS CSP のみに適用されることに注意してください。サードパーティの CSP を使用する場合、CryptoAPI は 5 バイトの指数で動作できるはずです。

ソース:

于 2014-12-15T13:36:40.767 に答える