Search code examples
c#bouncycastlepempkcs#10

Export a Pkcs10CertificationRequest object to a .pem file


I have been testing Bouncy Castle in C#. I have not found a way to export a Pkcs10CertificationRequest object to a .pem file. I have tried with PemWriter objects but I have not succeeded. It can be the code or some idea of ​​how to do it. Can someone help me. Thank you


Solution

  • You don't mention what version of BC you are using, but at least in recent versions it is directly supported by PemWriter:

    Pkcs10CertificationRequest pkcs10 = ...;
    FileStream file = ...;
    
    using (var w = new Org.BouncyCastle.OpenSsl.PemWriter(new StreamWriter(file)))
    {
        w.WriteObject(pkcs10);
    }