Last active
October 17, 2018 00:16
-
-
Save vcsjones/d70c1895e4c457a9c99d47b6700d17e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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