Skip to content

Instantly share code, notes, and snippets.

Created Sep 5, 2021
What would you like to do?
using System;
using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using var ecdsa = ECDsa.Create(ECCurve.NamedCurves.nistP256);
var req = new CertificateRequest("CN=Kevin Jones", ecdsa, HashAlgorithmName.SHA256);
req.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DigitalSignature, true));
new X509EnhancedKeyUsageExtension(new OidCollection {
new Oid("")
}, false)
var reqDer = req.CreateSigningRequest();
File.WriteAllText("reqest.pem", new string(PemEncoding.Write("CERTIFICATE REQUEST", reqDer)));
File.WriteAllText("key.pem", new string(PemEncoding.Write("PRIVATE KEY", ecdsa.ExportPkcs8PrivateKey())));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment