我正在使用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);
现在,接收这些数据的是一个Silverlight应用程序,并且正在使用RSACryptoServiceProvider
(System.Security.Cryptography
)来加载这个公钥:
RSACryptoServiceProvider rsaPublic = new RSACryptoServiceProvider();
byte[] keyBlobBytes = Convert.FromBase64String(keyBlob);
rsaPublic.ImportCspBlob(keyBlobBytes);
keyBlob是一个包含公钥的字节数组。问题在于当调用ImportCspBlob时,会抛出异常,提示“提供程序版本错误”。