I’ve found DLL’s ok, but I’m having trouble finding documentation.
I want to use C# to decrypt a string of text using a private RSA key. Documentation on OpenSSL.Net would be great, information on how to do this in particular would be amazing!
The string itself was in Base64, and my private key is stored in a *.pem file. My final method is below, based on LOSTCODER’s answer:
public string Decrypt(string textToDecrypt)
{
byte[] payLoad = Convert.FromBase64String(textToDecrypt);
StreamReader sr = new StreamReader("pemfilelocation.pem");
string privateKey = sr.ReadToEnd();
using (var key = CryptoKey.FromPrivateKey(privateKey, "myprivatekey"))
{
using (var rsa = key.GetRSA())
{
payLoad = rsa.PrivateDecrypt(payLoad, RSA.Padding.PKCS1);
}
}
return Encoding.UTF8.GetString(payLoad);
}
Use the following routine to decrypt a byte[] using RSA private key. If you want to pass your encrypted ‘string of text’, use
System.Text.Encoding.ASCII.GetBytes()to convert it to a byte[] (text is assumed to be ASCII encoded).