Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   [C#|OpenSSL] RSA is causing me headaches (http://www.go4expert.com/forums/c-sharpopenssl-rsa-causing-headaches-t25134/)

WolFSharp 3Mar2011 16:44

[C#|OpenSSL] RSA is causing me headaches
Hi, iam using an external library (OpenSSL.Crypto) to encrypt/decrypt files in my c# project.
I have to use RSA, but there is a lack of documentation, I tried to find an example but no way :nonod:
i tried by myself to explore the library and i wrote this code:

byte[] msg = System.Text.Encoding.ASCII.GetBytes("text to encrypt");
            OpenSSL.Crypto.Envelope env = new OpenSSL.Crypto.Envelope();
            OpenSSL.Crypto.RSA rsa = new OpenSSL.Crypto.RSA();
            Console.Write("{0}", env.PrivateKeyAsPEM);

Have any one used RSA before with this library?

E L N I N O 28Feb2012 18:49

Re: [C#|OpenSSL] RSA is causing me headaches
This is how you create a RSA key pair and use it to encrypt/decrypt a byte[]:

// Generate key pair
var rsa = new RSA();
rsa.GenerateKeys(2048, 0x10021, null, null);

// Encrypt file
byte[] payLoad = File.ReadAllBytes("c:\folder\myfile.ext");
byte[] encryptedResult = rsa.PublicEncrypt(payload, RSA.Padding.PKCS1);

// Decrypt file
byte[] decryptedResult = rsa.PrivateDecrypt(encryptedResult, RSA.Padding.PKCS1);

Hope this helps!

All times are GMT +5.5. The time now is 09:10.