Class Pem

java.lang.Object
com.codename1.backend.security.pki.Pem

public final class Pem extends Object

PEM, the base64 text form of DER that openssl reads and writes: one or more blocks between -----BEGIN <label>----- and -----END <label>-----.

List<Pem.Block> blocks = Pem.decode(fullChainPem);
String pem = Pem.encode(Pem.CERTIFICATE, certificate.getEncoded());

Text outside the blocks, such as the Bag Attributes lines openssl pkcs12 prints, is ignored. A block with RFC 1421 headers (an encrypted traditional key) is refused, since its content is not plain DER.

  • Field Details

  • Method Details

    • decode

      public static List<Pem.Block> decode(String pem) throws IOException
      Every block in pem, in order.
      Throws:
      IOException - when there is no block, a block is not closed, or a block's content is not base64
    • decode

      public static List<byte[]> decode(String pem, String label) throws IOException
      The DER of every block labelled label, in order; empty when there is none.
      Throws:
      IOException
    • encode

      public static String encode(String label, byte[] der)
      One block, with the base64 in 64 character lines as openssl writes it.