Class Pem.Encoder

  • Enclosing class:
    Pem

    public static class Pem.Encoder
    extends Object
    Encode certificates, public keys and private keys into PEM encoded format
    • Method Detail

      • with

        public Pem.Encoder with​(Pem.Format format)
        Configure a new instance with the specified PKCS format.

        Note that the format applies to private and public keys only. Certificates always use X509 PEM encoding.

        Parameters:
        format - The encoding format for public and private keys
        Returns:
        Encoder instance
      • with

        public Pem.Encoder with​(Pem.Encryption encryption)
        Configure an encoder to produce encrypted private keys.

        Encryption does not apply to public keys or certificates

        Parameters:
        encryption - The encryption configuration, or null if no encryption is required
        Returns:
        Encoder instance
      • with

        public Pem.Encoder with​(Pem.Passphrase passphrase)
        Configure an encoder to produce encrypted private keys.

        Encryption does not apply to public keys or certificates

        Parameters:
        passphrase - The encryption passphrase, or null if no encryption is required
        Returns:
        Encoder instance
      • encode

        public String encode​(PublicKey publicKey)
        Render a public key in PEM format using PKCS1
        Parameters:
        publicKey - The public key
        Returns:
        PEM encoding of the public key in PKCS1 format
      • encode

        public String encode​(Certificate certificate)
        Render a certificate in PEM format
        Parameters:
        certificate - The certificate
        Returns:
        PEM encoding of the certificate
      • encode

        public String encode​(Iterable<? extends Certificate> certificates)
        Render a certificate chain in PEM format
        Parameters:
        certificates - The certificates
        Returns:
        PEM encoding of the certificate chain
      • encode

        public byte[] encode​(PrivateKey privateKey)
        Render a private key in PEM format.

        The private key is sensitive data and is returned as a byte array. The caller is responsible for erasing the byte array after use.

        Parameters:
        privateKey - The private key
        Returns:
        The PEM encoded private key as UTF-8 encoded bytes