Ejemplo n.º 1
0
        /// <summary>
        /// Export a certificate to a PEM format string
        /// </summary>
        /// <param name="cert">The certificate to export</param>
        /// <returns>A PEM encoded string</returns>
        public static string ExportToPEM(System.Security.Cryptography.X509Certificates.X509Certificate cert)
        {
            System.Text.StringBuilder builder = new System.Text.StringBuilder();

            builder.AppendLine("-----BEGIN CERTIFICATE-----");
            builder.AppendLine(
                System.Convert.ToBase64String(
                    cert.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Cert)
                    , System.Base64FormattingOptions.InsertLineBreaks)
                );
            builder.AppendLine("-----END CERTIFICATE-----");

            return(builder.ToString());
        } // End Function ExportToPEM