Skip to content

Instantly share code, notes, and snippets.

@fearthecowboy
Created March 7, 2016 20:04
Show Gist options
  • Save fearthecowboy/63515a2dd523a836f8b6 to your computer and use it in GitHub Desktop.
Save fearthecowboy/63515a2dd523a836f8b6 to your computer and use it in GitHub Desktop.
MkCert
using System.IO;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using VCSJones.FiddlerCertGen;
namespace MkCert
{
internal class Program
{
private static void Main(string[] args)
{
var algorithm = Algorithm.RSA;
var signatureAlgorithm = HashAlgorithm.SHA384;
var keySize = 2048;
var keyName = $"Self-Signed-Key;";
var gen = new CertificateGenerator();
IPAddress localhost;
IPAddress.TryParse("127.0.0.1", out localhost);
IPAddress address;
IPAddress.TryParse("10.123.172.76", out address);
using (
var key = PrivateKey.CreateNew(KeyProviders.CNG, keyName, algorithm, KeyUsage.Signature, overwrite: true,
keySize: keySize))
{
var cert = gen.GenerateSelfSignedCertificate(key,
new X500DistinguishedName(
"CN=This is a Self-Signed certificate, O=DO_NOT_TRUST, OU=Created by script"),
signatureAlgorithm,
new[] {"lawman", "lawman.ntdev.corp.microsoft.com"}, new[] {localhost, address});
var bytes = cert.Export(X509ContentType.Pkcs12, "password");
File.WriteAllBytes(@"c:\temp\cert.pfx", bytes);
bytes = cert.Export(X509ContentType.Cert);
File.WriteAllBytes(@"c:\temp\cert.cer", bytes);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment