Write x509 certificate into PEM formatted string in java?

后端 未结 10 2296
天涯浪人
天涯浪人 2020-12-07 15:48

Is there some high level way to write an X509Certificate into a PEM formatted string? Currently I\'m doing x509cert.encode() to write it into a DER formatted string, then ba

10条回答
  •  粉色の甜心
    2020-12-07 16:28

    This is not bad. Java doesn't provide any functions to write PEM files. What you are doing is the correct way. Even KeyTool does the same thing,

    BASE64Encoder encoder = new BASE64Encoder();
    out.println(X509Factory.BEGIN_CERT);
    encoder.encodeBuffer(cert.getEncoded(), out);
    out.println(X509Factory.END_CERT);
    

    If you use BouncyCastle, you can use PEMWriter class to write out X509 certificate in PEM.

提交回复
热议问题