Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a certificate with OpenSSL.net

Tags:

c#

openssl

I use C #. net in programming. My problem is using a OpenSSL.net to create certificate Personal and CA and signed personally certificate by a private key of CA.

I have already managed the integrated OpenSSL.net in my project, but I can not find the line of code to create the certificate.

How do I create a certificate with OpenSSL.net?

like image 218
user721036 Avatar asked Nov 21 '25 16:11

user721036


1 Answers

Try this one:

 X509Name issuer = new X509Name("issuer");

 X509Name subject = new X509Name("subject");
 RSA rsa = new RSA();
 rsa.GenerateKeys(512,0x10021,null,null);
 CryptoKey key = new CryptoKey(rsa);

 X509Certificate cert = new X509Certificate(123, subject, issuer, key, DateTime.Now,
                                                       DateTime.Now.AddDays(200));

 File.WriteAllText("C:\\temp\\public.txt",rsa.PublicKeyAsPEM);
 File.WriteAllText("C:\\temp\\private.txt", rsa.PrivateKeyAsPEM);

 BIO bio = BIO.File("C:/temp/cert.cer", "w");
 cert.Write(bio);

X509Certificate is creating a certificate; cert.Write writes this certificate to a file.

like image 132
Dmitriy Avatar answered Nov 24 '25 06:11

Dmitriy



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!