简体   繁体   English

在哪里可以找到有关OpenSSL.Net的文档

[英]Where can I find documentation on OpenSSL.Net

I've found DLL's ok, but I'm having trouble finding documentation. 我发现DLL没问题,但是找不到文档。

I want to use C# to decrypt a string of text using a private RSA key. 我想使用C#使用私有RSA密钥解密文本字符串。 Documentation on OpenSSL.Net would be great, information on how to do this in particular would be amazing! OpenSSL.Net上的文档非常棒,特别是有关如何执行此操作的信息将非常棒!

Edit: 编辑:

The string itself was in Base64, and my private key is stored in a *.pem file. 字符串本身在Base64中,我的私钥存储在* .pem文件中。 My final method is below, based on LOSTCODER's answer: 根据LOSTCODER的答案,我的最终方法如下:

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. 使用以下例程使用RSA私钥解密byte []。 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). 如果要传递加密的“文本字符串”,请使用System.Text.Encoding.ASCII.GetBytes()将其转换为byte [](假定文本为ASCII编码)。

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);
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM