Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenSSL .NET c# wrapper X509 certification

Hi Iam using the OpenSSL .NET wrapper in my c# project. i want to generate an X509 certification but i don't really know the procedure. what should it contain (what parameters)...etc this is my code, I did it after looking some tests:

        OpenSSL.X509.X509Certificate x509 = new OpenSSL.X509.X509Certificate();
        OpenSSL.Crypto.RSA rsa = new OpenSSL.Crypto.RSA();
        rsa.GenerateKeys(1024, 0x10001, null, null);
        OpenSSL.Crypto.CryptoKey key = new OpenSSL.Crypto.CryptoKey(rsa);
        OpenSSL.Crypto.MessageDigestContext digest = new OpenSSL.Crypto.MessageDigestContext(
                                                                 OpenSSL.Crypto.MessageDigest.SHA1);

I suppose that the certificate should take RSA private key and the digest as parameters and i have to configure it (date...and others parameters). Can any one help me about that ? to finish my code ? thank you.

like image 770
WolFSharp Avatar asked Feb 18 '26 11:02

WolFSharp


1 Answers

I use the following routine:

// Initialize the following with your information
var serial = 1234;
var issuer = new X509Name("issuer");
var subject = new X509Name("subject");

// Creates the key pair
var rsa = new RSA();
rsa.GenerateKeys(1024, 0x10001, null, null);

// Creates the certificate
var key = new CryptoKey(rsa);
var cert = new X509Certificate(serial, subject, issuer, key, DateTime.Now, DateTime.Now.AddYears(20));

// Dumps the certificate into a .cer file
var bio = BIO.File("C:/temp/cert.cer", "w");
cert.Write(bio);
like image 132
Ε Г И І И О Avatar answered Feb 21 '26 01:02

Ε Г И І И О



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!