CertificateFormatter { public static String pemOf(final Object pemObject) throws IOException { final StringWriter sw = new StringWriter(); final JcaPEMWriter writer = new JcaPEMWriter(sw); writer.writeObject(pemObject); writer.close(); return sw.toString(); } private  CertificateFormatter(); static String pemOf(final Object pemObject); static String derOf(final RSAPublicKey publicKey); static final String SSH_RSA; }
@Test public void pemOf_convertsAnObjectToPemString() throws IOException { final String pemString = CertificateFormatter.pemOf(keyPair); assertThat(pemString, startsWith("-----BEGIN RSA PRIVATE KEY-----")); assertThat(pemString, endsWith("-----END RSA PRIVATE KEY-----\n")); }