"糟糕的提供商版本." 使用RSACryptoServiceProvider加载公钥时

tav*_*ier 7 c# rsa rsacryptoserviceprovider encryption-asymmetric

我正在使用AsymmetricKeyAlgorithmProvider(Windows.Security.Cryptography.Core)创建RSA密钥对并导出密钥,如下所示:

  AsymmetricKeyAlgorithmProvider rsaGenKeys = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaPkcs1);

  CryptographicKey keyPair = rsaGenKeys.CreateKeyPair(2048);
  byte[] privateKeyBlob = keyPair.Export(CryptographicPrivateKeyBlobType.Pkcs1RsaPrivateKey).ToArray();

  string privateKeyBlobStr = Convert.ToBase64String(privateKeyBlob);

  byte[] publicKeyBlob = keyPair.ExportPublicKey().ToArray();

  string pubilcKeyBlobStr = Convert.ToBase64String(publicKeyBlob);
Run Code Online (Sandbox Code Playgroud)

现在,这个数据的接收者恰好是一个Silverlight应用程序,并使用RSACryptoServiceProvider(System.Security.Cryptography)来加载这个公钥:

RSACryptoServiceProvider rsaPublic = new RSACryptoServiceProvider();
byte[] keyBlobBytes = Convert.FromBase64String(keyBlob);
rsaPublic.ImportCspBlob(keyBlobBytes);
Run Code Online (Sandbox Code Playgroud)

其中keyBlob是具有公钥的字节数组.问题是当调用ImportCspBlob时,它会抛出异常,说"提供商的错误版本".

小智 1

我有同样的错误。由于某种原因,FxSSH 不喜欢我生成的 RSA 公钥。我必须使用https://github.com/Aimeast/FxSsh自述文件中的 RSA 密钥。