mirror of
https://github.com/MAKS-IT-COM/maksit-certs-ui.git
synced 2025-12-31 04:00:03 +01:00
27 lines
803 B
C#
27 lines
803 B
C#
using System;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Text;
|
|
|
|
|
|
namespace LetsEncrypt
|
|
{
|
|
class Library
|
|
{
|
|
/// <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(X509Certificate cert)
|
|
{
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
builder.AppendLine("-----BEGIN CERTIFICATE-----");
|
|
builder.AppendLine(Convert.ToBase64String(cert.Export(X509ContentType.Cert), Base64FormattingOptions.InsertLineBreaks));
|
|
builder.AppendLine("-----END CERTIFICATE-----");
|
|
|
|
return builder.ToString();
|
|
}
|
|
}
|
|
}
|