Class PEM
- All Implemented Interfaces:
BinaryEncodablePREVIEW
public final class PEM extends Object implements BinaryEncodablePREVIEW
PEM is a preview API of the Java platform. 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
| Constructor | Description |
|---|---|
PEM |
Creates a PEM instance with the specified type and Base64-encoded content byte array. |
PEM |
Creates a PEM instance with the specified type and Base64-encoded content and leading data as byte arrays. |
PEM |
Creates a PEM instance with the specified type and Base64-encoded content string. |
PEM |
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[] |
content() |
Returns the Base64-encoded content. |
byte[] |
decode() |
Returns the Base64-decoded content as a byte array, using Base64.getMimeDecoder(). |
byte[] |
leadingData() |
Returns the leading data that preceded the PEM header in the decoded input. |
String |
toString() |
Returns a PEM string representation of this object, using type for the header and footer lines and content for the Base64 body. |
String |
type() |
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 |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Constructor Details
PEM
public PEM(String type, String base64Content, byte[] leadingData)
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- iftypecontains PEM encapsulation syntax -
NullPointerException- if any parameter isnull
PEM
public PEM(String type, String base64Content)
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- iftypecontains PEM encapsulation syntax -
NullPointerException- if any parameter isnull
PEM
public PEM(String type, byte[] base64Content, byte[] leadingData)
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- iftypecontains PEM encapsulation syntax -
NullPointerException- if any parameter isnull - Since:
- 27
PEM
public PEM(String type, byte[] base64Content)
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- iftypecontains PEM encapsulation syntax -
NullPointerException- if any parameter isnull - Since:
- 27
Method Details
type
public String type()
- Returns:
- the PEM type identifier
leadingData
public byte[] leadingData()
- Returns:
- a newly-allocated byte array containing leading data, or
nullif no leading data is present
content
public byte[] content()
- Returns:
- a newly-allocated byte array containing the Base64 content
- Since:
- 27
decode
public byte[] decode()
Base64.getMimeDecoder().- Returns:
- a newly-allocated byte array containing the decoded content
- Throws:
-
IllegalArgumentException- if decoding fails
toString
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
PEMwhen preview features are enabled.