【发布时间】:2011-11-06 05:49:58
【问题描述】:
我有以下代码使用 OpenSSL.Net 生成 OpenSSL RSA 公钥和私钥。但是,我似乎找不到使用给定私钥解密数据的方法。我知道如果我调用生成密钥,然后调用相应的方法来加密和解密数据,它就可以正常工作。但是,如果我试图从给定公钥的外部源解密某些内容,我该如何使用该密钥解密。
注意:请不要给出不使用 OpenSSL.NET 的示例。 Microsoft Cryptographic 提供程序比 OpenSSL 慢得多,不符合我的速度要求。
谢谢!
public class AsymmetricKeyResult
{
public string PublicKey { get; set; }
public string PrivateKey { get; set; }
public AsymmetricKeyResult(string publicKey, string privateKey)
{
this.PublicKey = publicKey;
this.PrivateKey = privateKey;
}
}
public static AsymmetricKeyResult GenerateAsymmetricKeys(int keyLength)
{
RSA rsa = new RSA();
rsa.GenerateKeys(keyLength, 0x10021, null, null);
AsymmetricKeyResult kResult = new AsymmetricKeyResult(rsa.PublicKeyAsPEM, rsa.PrivateKeyAsPEM);
return kResult;
}
【问题讨论】:
标签: c# encryption openssl rsa