code: public static void writeCertificate(
              OutputStream out,
              X509Certificate cert)
              throws IOException, CertificateEncodingException {
          PEMUtil.writeBase64(out,
                  "-----BEGIN CERTIFICATE-----",
                  Base64.encode(cert.getEncoded()),
                  "-----END CERTIFICATE-----");
      }
docs: Writes certificate to the specified output stream in PEM format.