public static String pemEncodeX509Certificate(X509Certificate cert) throws IOException {
    StringWriter stringWriter = new StringWriter();
    JcaPEMWriter pemWriter = new JcaPEMWriter(stringWriter);
    pemWriter.writeObject(cert);
    pemWriter.close();
    return stringWriter.toString();
  }
PEM-encodes the given X509 certificate (compatible with OpenSSL) and returns the result as a
String.
@param cert the certificate.
@return a String containing the PEM encoding of the certificate.
@throws IOException if converting the certificate to PEM format fails.
hbase-common/src/test/java/org/apache/hadoop/hbase/io/crypto/tls/X509TestHelpers.java