Class PEM

java.lang.Object
java.security.PEM
All Implemented Interfaces:
BinaryEncodablePREVIEW

public final class PEM extends Object implements BinaryEncodablePREVIEW
PEM is a preview API of the Java platform.
Programs can only use PEM when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A BinaryEncodablePREVIEW representing a Privacy-Enhanced Mail (PEM) structure composed of a type identifier, Base64-encoded content, and optional leading data that precedes the PEM header.

The type is the label in the PEM header, following the BEGIN keyword and excluding the encapsulation boundaries. Common type values include, but are not limited to: CERTIFICATE, CERTIFICATE REQUEST, ATTRIBUTE CERTIFICATE, X509 CRL, PKCS7, CMS, PRIVATE KEY, ENCRYPTED PRIVATE KEY, and PUBLIC KEY.

Instances of this class are returned by PEMDecoder.decode(String)PREVIEW and PEMDecoder.decode(InputStream)PREVIEW when the content cannot be represented as a cryptographic object. To explicitly retrieve a PEM instance with access to the leading data, use PEMDecoder.decode(String, Class)PREVIEW or PEMDecoder.decode(InputStream, Class)PREVIEW with PEM.class as the type.

A PEM object can be encoded to its textual representation by invoking toString() or by using PEMEncoderPREVIEW.

To construct a PEM instance, type and base64Content must be non-null. For constructors that accept leadingData, it must also be non-null.

No validation is performed to ensure that the type conforms to RFC 7468 or legacy formats, or that the content corresponds to the declared type.

Since:
26
External Specifications
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    PEM(String type, byte[] base64Content)
    Creates a PEM instance with the specified type and Base64-encoded content byte array.
    PEM(String type, byte[] base64Content, byte[] leadingData)
    Creates a PEM instance with the specified type and Base64-encoded content and leading data as byte arrays.
    PEM(String type, String base64Content)
    Creates a PEM instance with the specified type and Base64-encoded content string.
    PEM(String type, String base64Content, byte[] leadingData)
    Creates a PEM instance with the specified type, Base64-encoded content string, and leading data byte array.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Returns the Base64-encoded content.
    byte[]
    Returns the Base64-decoded content as a byte array, using Base64.getMimeDecoder().
    byte[]
    Returns the leading data that preceded the PEM header in the decoded input.
    Returns a PEM string representation of this object, using type for the header and footer lines and content for the Base64 body.
    Returns the PEM type identifier.

    Methods declared in class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
    Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.
    boolean
    Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    May cause performance issues, deadlocks and hangs.
    final Class<? extends Object>
    Answers the unique instance of java.lang.Class which represents the class of the receiver.
    int
    Answers an integer hash code for the receiver.
    final void
    Causes one thread which is waiting on the receiver to be made ready to run.
    final void
    Causes all threads which are waiting on the receiver to be made ready to run.
    final void
    Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated by notify or notifyAll).
    final void
    wait(long time)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
    final void
    wait(long time, int frac)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
  • Constructor Details

    • PEM

      public PEM(String type, String base64Content, byte[] leadingData)
      Creates a PEM instance with the specified type, Base64-encoded content string, and leading data byte array.
      Parameters:
      type - the PEM type identifier; must not contain PEM encapsulation syntax
      base64Content - the Base64-encoded content, excluding the PEM header and footer
      leadingData - data that precedes the PEM header. This array is defensively copied.
      Throws:
      IllegalArgumentException - if type contains PEM encapsulation syntax
      NullPointerException - if any parameter is null
    • PEM

      public PEM(String type, String base64Content)
      Creates a PEM instance with the specified type and Base64-encoded content string.
      Parameters:
      type - the PEM type identifier; must not contain PEM encapsulation syntax
      base64Content - the Base64-encoded content, excluding the PEM header and footer
      Throws:
      IllegalArgumentException - if type contains PEM encapsulation syntax
      NullPointerException - if any parameter is null
    • PEM

      public PEM(String type, byte[] base64Content, byte[] leadingData)
      Creates a PEM instance with the specified type and Base64-encoded content and leading data as byte arrays.
      Parameters:
      type - the PEM type identifier; must not contain PEM encapsulation syntax
      base64Content - the Base64-encoded content, excluding the PEM header and footer. This array is defensively copied.
      leadingData - data that precedes the PEM header. This array is defensively copied.
      Throws:
      IllegalArgumentException - if type contains PEM encapsulation syntax
      NullPointerException - if any parameter is null
      Since:
      27
    • PEM

      public PEM(String type, byte[] base64Content)
      Creates a PEM instance with the specified type and Base64-encoded content byte array.
      Parameters:
      type - the PEM type identifier; must not contain PEM encapsulation syntax
      base64Content - the Base64-encoded content, excluding the PEM header and footer. This array is defensively copied.
      Throws:
      IllegalArgumentException - if type contains PEM encapsulation syntax
      NullPointerException - if any parameter is null
      Since:
      27
  • Method Details

    • type

      public String type()
      Returns the PEM type identifier.
      Returns:
      the PEM type identifier
    • leadingData

      public byte[] leadingData()
      Returns the leading data that preceded the PEM header in the decoded input.
      Returns:
      a newly-allocated byte array containing leading data, or null if no leading data is present
    • content

      public byte[] content()
      Returns the Base64-encoded content.
      Returns:
      a newly-allocated byte array containing the Base64 content
      Since:
      27
    • decode

      public byte[] decode()
      Returns the Base64-decoded content as a byte array, using Base64.getMimeDecoder().
      Returns:
      a newly-allocated byte array containing the decoded content
      Throws:
      IllegalArgumentException - if decoding fails
    • toString

      public String toString()
      Returns a PEM string representation of this object, using type for the header and footer lines and content for the Base64 body.
      Overrides:
      toString in class Object
      Returns:
      the PEM-formatted string