我使用openssl在服务器端创建密钥对。
string serverPublicKey;
string serverPrivateKey;
using (var serverRsa = new OpenSSL.Crypto.RSA())
{
serverRsa.GenerateKeys(512, 65537, null, null);
serverPublicKey = serverRsa.PublicKeyAsPEM;
serverPrivateKey = serverRsa.PrivateKeyAsPEM;
}
在客户端(Xamarin)我想用PCLCrypto导入公钥,但我总是得到错误"意外的格式或不支持的密钥",请参阅下面的代码。
var publicServerKey = _serverKeys.RsaKey;
var keyBuffer = Encoding.UTF8.GetBytes(publicServerKey);
var asym = WinRTCrypto.AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithm.RsaPkcs1);
var key = asym.ImportPublicKey(keyBuffer, CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey);
如何导入公钥,加密数据?