# Record Class PEMRecord

java.lang.Object
java.lang.Record
java.security.PEMRecord

Record Components:
  `type` - the type identifier in the PEM header without PEM syntax labels. For a public key, `type` would be "PUBLIC KEY".
  `content` - the Base64-encoded data, excluding the PEM header and footer
  `leadingData` - any non-PEM data preceding the PEM header when decoding.

All Implemented Interfaces:
  `DEREncodablePREVIEW`

public record PEMRecord(String type, String content, byte[] leadingData) extends Record implements DEREncodablePREVIEW
`PEMRecord` is a preview API of the Java platform.
Programs can only use `PEMRecord` when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
`PEMRecord` is a `DEREncodable`PREVIEW that represents Privacy-Enhanced Mail (PEM) data by its type and Base64 form. `PEMDecoder`PREVIEW and `PEMEncoder`PREVIEW use `PEMRecord` when representing the data as a cryptographic object is not desired or the type has no `DEREncodable`.

`type` and `content` may not be `null`. `leadingData` may be null if no non-PEM data preceded PEM header during decoding. `leadingData` may be useful for reading metadata that accompanies PEM data.

No validation is performed during instantiation to ensure that `type` conforms to `RFC 7468`, that `content` is valid Base64, or that `content` matches the `type`. `leadingData` is not defensively copied and does not return a clone when leadingData() is called.

Since:
  25
External Specifications
  - RFC 7468: Textual Encodings of PKIX, PKCS, and CMS Structures
See Also:
  - `PEMDecoder`PREVIEW
  - `PEMEncoder`PREVIEW

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PEMRecord(String type, String content)`
  Creates a `PEMRecord` instance with a given `type` and `content` data in String form.
  `PEMRecord(String type, String content, byte[] leadingData)`
  Creates a `PEMRecord` instance with the given parameters.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `content()`
  Returns the value of the `content` record component.
  `final boolean`
  `equals(Object o)`
  Indicates whether some other object is "equal to" this one.
  `final int`
  `hashCode()`
  Returns a hash code value for this object.
  `byte[]`
  `leadingData()`
  Returns the value of the `leadingData` record component.
  `String`
  `toString()`
  Returns the type and Base64 encoding in PEM format.
  `String`
  `type()`
  Returns the value of the `type` record component.

  ### Methods declared in class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### PEMRecord

    public PEMRecord(String type, String content, byte[] leadingData)
    Creates a `PEMRecord` instance with the given parameters.
    Parameters:
      `type` - the type identifier
      `content` - the Base64-encoded data, excluding the PEM header and footer
      `leadingData` - any non-PEM data read during the decoding process before the PEM header. This value maybe `null`.
    Throws:
      `IllegalArgumentException` - if `type` is incorrectly formatted.
      `NullPointerException` - if `type` and/or `content` are `null`.

  - ### PEMRecord

    public PEMRecord(String type, String content)
    Creates a `PEMRecord` instance with a given `type` and `content` data in String form. `leadingData` is set to null.
    Parameters:
      `type` - the PEM type identifier
      `content` - the Base64-encoded data, excluding the PEM header and footer
    Throws:
      `IllegalArgumentException` - if `type` is incorrectly formatted.
      `NullPointerException` - if `type` and/or `content` are `null`.

- ## Method Details

  - ### toString

    public String toString()
    Returns the type and Base64 encoding in PEM format. `leadingData` is not returned by this method.
    Specified by:
      `toString` in class `Record`
    Returns:
      a string representation of the object.
    See Also:
      - `Object.toString()`

  - ### hashCode

    public final int hashCode()
    Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
    Specified by:
      `hashCode` in class `Record`
    Returns:
      a hash code value for this object
    See Also:
      - `Object.hashCode()`

  - ### equals

    public final boolean equals(Object o)
    Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with `Objects::equals(Object,Object)`.
    Specified by:
      `equals` in class `Record`
    Parameters:
      `o` - the object with which to compare
    Returns:
      `true` if this object is the same as the `o` argument; `false` otherwise.
    See Also:
      - `Objects.equals(Object,Object)`

  - ### type

    public String type()
    Returns the value of the `type` record component.
    Returns:
      the value of the `type` record component

  - ### content

    public String content()
    Returns the value of the `content` record component.
    Returns:
      the value of the `content` record component

  - ### leadingData

    public byte[] leadingData()
    Returns the value of the `leadingData` record component.
    Returns:
      the value of the `leadingData` record component