View Source PEM (PEM v0.1.0)

Implementation of rfc7468 (https://tools.ietf.org/html/rfc7468) encoding and decoding of PEM binaries.

Link to this section Summary

Functions

Decodes the given PEM encoded content.

Encodes the given content with the given label.

Link to this section Functions

Link to this function

decode(content, options \\ [])

View Source

Decodes the given PEM encoded content.

iex> PEM.decode("-----BEGIN TEST-----\nSGVsbG8gV29ybGQ=\n-----END TEST-----\n")
{:ok, "Hello World"}

You can optionally pass strict: true to enforce stricter validation of the PEM content.

iex> PEM.decode("-----BEGIN TEST1-----\nSGVsbG8gV29ybGQ=\n-----END TEST2-----\n", strict: true)
{:error, :different_labels}

You can also pass enforce_label: "" to enforce the label of the PEM content.

iex> PEM.decode("-----BEGIN TEST-----\nSGVsbG8gV29ybGQ=\n-----END TEST-----\n", enforce_label: "TEST1")
{:error, :header_label_mismatch}
Link to this function

encode(content, label, options \\ [])

View Source

Encodes the given content with the given label.

iex> PEM.encode("Hello World", "TEST")
"-----BEGIN TEST-----
SGVsbG8gV29ybGQ=
-----END TEST-----
"