I have the following code below to generate an OpenSSL RSA public and private key using OpenSSL.Net. However, I can’t seem to find a way to decrypt data with a given private key. I know if I call generate keys and then the corresponding methods to encrypt and decrypt the data it works fine. However, if I am trying to decrypt something from an external source given a public key, how can I decrypt using that key.
Note: Please do not give examples that don’t use OpenSSL.NET. The Microsoft Cryptographic providers are far slower than OpenSSL and do not meet my speed requirements.
Thanks!
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;
}
I ended up figuring it out through the object browser on the Managed Wrapper for OpenSSL.NET. This works: