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时,它会抛出异常,说"提供商的错误版本".
| 归档时间: |
|
| 查看次数: |
2051 次 |
| 最近记录: |