Package org.bzdev.net

Class PemEncoder

java.lang.Object
org.bzdev.net.PemEncoder

public class PemEncoder extends Object
PEM Encoder class. This class will encode data using the PEM format described in RFC 7468 and RFC 1421. The PEM-encoded data may be preceded or followed by headers that consist of a key, followed by a colon, followed by a value.
  • Constructor Details

    • PemEncoder

      public PemEncoder(Appendable out)
      Constructor. When called directly, the EOL sequence will be CRLF.
      Parameters:
      out - the Appendable used for output
    • PemEncoder

      public PemEncoder(Appendable out, PemEncoder.EOL eol)
      Constructor specifying the end-of-line sequence.
      Parameters:
      out - the Appendable used for output
      eol - PemEncoder.EOL.CRLF if lines are terminated with a carriage return followed by a line feed; PemEncoder.EOL.CR if lines are terminated with a carriage return; PemEncoder.EOL.LFif lines are terminated with a line feed
  • Method Details

    • addHeader

      public void addHeader(String key, String value) throws IOException
      Add a header. Names must consist of only letters, digits, underscores, or a minus. Values must contain only a single line of text without any new-line characters or any character denoting a vertical change in position in the text. In both cases, the characters should be those in the US ASCII character set.

      Note that RFC 7468 allows data to be inserted before the encapsulated encoding.

      Parameters:
      key - the name of the header
      value - the value of the header
      Throws:
      IOException
    • encode

      public void encode(String type, byte[] data) throws IOException, IllegalArgumentException, NullPointerException
      Encode data using PEM format.
      Parameters:
      type - the type of the data
      data - the data to be encoded
      Throws:
      IOException - if an IO error occurs
      NullPointerException - if an argument is null
      IllegalArgumentException - if the first argument contains only whitespace or if it contains a minus