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!
Edit:
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);
}
Thankyou
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).
private static byte[] Decrypt(byte[] payLoad, string privateKey)
{
using (var key = OpenSSL.Crypto.CryptoKey.FromPrivateKey(privateKey, null))
{
using (var rsa = key.GetRSA())
{
return rsa.PrivateDecrypt(payLoad, OpenSSL.Crypto.RSA.Padding.PKCS1);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.