0

I add an OpenSSL package(System.Security.Cryptography.OpenSsl) to my .net core project in NuGet, but I don't know how to use it.Please give me some tips.Thank you!!!

thonfun
  • 1
  • 1
  • 1
  • This isn't really a question so I wouldn't expect much. Why don't you goggle "asp.net core OpenSSL examples" and see what you get. Then do some work and ask questions that are more directed. – GlennSills Jun 11 '21 at 13:06
  • Can you tell us what you want to do by using the OpenSSL package, Create a self-signed certificate? – Zhi Lv Jun 15 '21 at 08:05
  • Does this answer your question? [How to create a valid, self-signed X509Certificate2 programmatically, not loading from file in .NET Core](https://stackoverflow.com/questions/42786986/how-to-create-a-valid-self-signed-x509certificate2-programmatically-not-loadin) – Elikill58 Oct 06 '21 at 17:08

1 Answers1

0

(You need to be on .net framework 4.7.2 or more)

I was searching for the same thing, and I found :

// Here we define content which will be in certificate like name or state
X500DistinguishedName distinguishedName = new X500DistinguishedName("C=" + countryCode + ",ST=" + state + ",L=" + locality + ",O=" + organization + ",CN=" + fullName);

using (RSA rsa = RSA.Create()) { // create RSA key
    CertificateRequest request = new CertificateRequest(distinguishedName, rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

    request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature, false));


    request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection { new Oid("1.3.6.1.5.5.7.3.1") }, false));

    X509Certificate2 certificate = request.CreateSelfSigned(new DateTimeOffset(DateTime.UtcNow.AddDays(-1)), new DateTimeOffset(DateTime.UtcNow.AddDays(3650)));
    
    // Now let's get files:
    byte[] cert = certificate.Export(X509ContentType.Cert, password); //.crt
    byte[] p12 = certificate.Export(X509ContentType.Pkcs12, password); //.p12
}

Source: https://stackoverflow.com/a/50138133/10952503

Elikill58
  • 4,050
  • 24
  • 23
  • 45