Exporting a Certificate as BASE-64 encoded .cer

前端 未结 4 703
青春惊慌失措
青春惊慌失措 2020-12-08 19:13

I am trying to export a cert without the private key as as BASE-64 encoded file, same as exporting it from windows. When exported from windows I am able to open the .cer fil

4条回答
  •  离开以前
    2020-12-08 19:37

    Perhaps

    /// 
    /// Export a certificate to a PEM format string
    /// 
    /// The certificate to export
    /// A PEM encoded string
    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();
    }
    

提交回复
热议问题