Skip to content

Instantly share code, notes, and snippets.

@vcsjones
Created Sep 5, 2021
Embed
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));
req.CertificateExtensions.Add(
new X509EnhancedKeyUsageExtension(new OidCollection {
new Oid("1.3.6.1.5.5.7.3.3")
}, 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