Class PemUtil

java.lang.Object
org.cryptacular.util.PemUtil

public final class PemUtil extends Object
Utility class with helper methods for common PEM encoding operations.
Author:
Middleware Services
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    decode(byte[] pem)
    Decodes a PEM-encoded cryptographic object into the raw bytes of its ASN.1 encoding.
    static byte[]
    Decodes one or more PEM-encoded cryptographic objects into the raw bytes of their ASN.1 encoding.
    static boolean
    isBase64Char(byte b)
    Determines whether the given byte represents an ASCII character in the character set for base64 encoding.
    static boolean
    isPem(byte[] data)
    Determines whether the data in the given byte array is base64-encoded data of PEM encoding.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isPem

      public static boolean isPem(byte[] data)
      Determines whether the data in the given byte array is base64-encoded data of PEM encoding. The determination is made using as little data from the given array as necessary to make a reasonable determination about encoding.
      Parameters:
      data - Data to test for PEM encoding
      Returns:
      True if data appears to be PEM encoded, false otherwise.
    • isBase64Char

      public static boolean isBase64Char(byte b)
      Determines whether the given byte represents an ASCII character in the character set for base64 encoding.
      Parameters:
      b - Byte to test.
      Returns:
      True if the byte represents an ASCII character in the set of valid characters for base64 encoding, false otherwise. The padding character '=' is not considered valid since it may only appear at the end of a base64 encoded value.
    • decode

      public static byte[] decode(byte[] pem)
      Decodes a PEM-encoded cryptographic object into the raw bytes of its ASN.1 encoding. Header/footer data and metadata info, e.g. Proc-Type, are ignored.
      Parameters:
      pem - Bytes of PEM-encoded data to decode.
      Returns:
      ASN.1 encoded bytes.
    • decode

      public static byte[] decode(String pem)
      Decodes one or more PEM-encoded cryptographic objects into the raw bytes of their ASN.1 encoding. All header and metadata, e.g. Proc-Type, are ignored. If multiple cryptographic objects are represented, the decoded bytes of each object are concatenated together and returned.
      Parameters:
      pem - PEM-encoded data to decode.
      Returns:
      ASN.1 encoded bytes.