Search code examples
javacryptographybouncycastlex509

Convert der to pem through bouncy castle library


I found many answers towards convert from pem to der.

However, I cannot find ways to convert der to pem.

for example, the following codes generates der encoded file pkcs10.cer

public static void main(String[] args) throws Exception
{
    X509Certificate[] chain = buildChain();
    PEMWriter pemWrt = new PEMWriter(new OutputStreamWriter(System.out));
    pemWrt.writeObject(chain[0]);

    FileWriter fwO = new FileWriter("pkcs10.cer");
    fwO.write((chain[0]).toString());

    fwO.close();
    pemWrt.close();

}

Like, [0] Version: 3 SerialNumber: 1353995641265 IssuerDN: CN=Test Certificate Start Date: Mon Nov 26 21:54:01 PST 2012 Final Date: Mon Nov 26 21:54:51 PST 2012

However, I don't know how to make pem encoded Certification from der files.


Solution

  • I'm not a Java developer, and therefore I cannot show you code or point to a class. PEM is just the Base64 encoding of the binary DER, with a standard header and trailer.