Skip to content

Instantly share code, notes, and snippets.

@vcsjones
Last active October 17, 2018 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcsjones/d70c1895e4c457a9c99d47b6700d17e6 to your computer and use it in GitHub Desktop.
Save vcsjones/d70c1895e4c457a9c99d47b6700d17e6 to your computer and use it in GitHub Desktop.
static void Main(string[] args)
{
var cert = new X509Certificate2("foo.cer"); //Or however you load the certificate.
var octets = cert.Export(X509ContentType.Cert);
var formatted = Convert.ToBase64String(octets);
var builder = new StringBuilder();
builder.AppendLine("-----BEGIN CERTIFICATE-----");
var i = 0;
while(i < formatted.Length)
{
const int MAX_LINE_SIZE = 64;
var size = Math.Min(MAX_LINE_SIZE, formatted.Length - i);
builder.AppendLine(formatted.Substring(i, size));
i += size;
}
builder.AppendLine("-----END CERTIFICATE-----");
Console.WriteLine(builder);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment