Exemple #1
0
        public static string ToPem(this byte[] buffer, PemFormatLabel format)
        {
            var sb    = new StringBuilder();
            var label = format.ToLabel();

            sb.AppendLine($"-----BEGIN {label}-----");
            sb.AppendLine(string.Join("\n", Base64PEMLineBreaks.Matches(Convert.ToBase64String(buffer))));
            sb.AppendLine($"-----END {label}-----");
            return(sb.ToString());
        }
        public static string ToLabel(this PemFormatLabel formatLabel)
        {
            switch (formatLabel)
            {
            case PemFormatLabel.Certificate: return("CERTIFICATE");

            case PemFormatLabel.PublicKey: return("PUBLIC KEY");

            case PemFormatLabel.RsaPrivateKey: return("RSA PRIVATE KEY");
            }
            return(null);
        }