question: public static String toPEMformat ( X509Certificate certificate ) { StringWriter sw = new StringWriter ( ) ; PEMWriter pemWriter = new PEMWriter ( sw ) ; try { pemWriter . writeObject ( certificate ) ; pemWriter . close ( ) ; return sw . toString ( ) ; } catch ( IOException x ) { throw new RuntimeException ( "Failed to serialize certificate" , x ) ; } }
target:  Serialize Certificate in PEM format