ddn.crypto.encoding.pem

PEM encoding and decoding helpers.

Provides Base64 encode/decode (RFC 4648), PEM armor wrapping/unwrapping, and standard PEM label constants for cryptographic objects.

Types 2

structPemBlock

A decoded PEM block.

Fields
string labelThe PEM label (e.g. "RSA PRIVATE KEY").
ubyte[] derDataThe decoded DER bytes.
enumPemLabel : string

Standard PEM label constants for cryptographic objects.

RSA_PRIVATE_KEY = "RSA PRIVATE KEY"
RSA_PUBLIC_KEY = "RSA PUBLIC KEY"
EC_PRIVATE_KEY = "EC PRIVATE KEY"
ECDSA_PUBLIC_KEY = "ECDSA PUBLIC KEY"
PRIVATE_KEY = "PRIVATE KEY"
PUBLIC_KEY = "PUBLIC KEY"
ENCRYPTED_PRIVATE_KEY = "ENCRYPTED PRIVATE KEY"
CERTIFICATE = "CERTIFICATE"
CERTIFICATE_REQUEST = "CERTIFICATE REQUEST"
DH_PARAMETERS = "DH PARAMETERS"
PKCS7 = "PKCS7"
ED25519_PRIVATE_KEY = "ED25519 PRIVATE KEY"
ED25519_PUBLIC_KEY = "ED25519 PUBLIC KEY"
X25519_PRIVATE_KEY = "X25519 PRIVATE KEY"
X25519_PUBLIC_KEY = "X25519 PUBLIC KEY"
X448_PRIVATE_KEY = "X448 PRIVATE KEY"
X448_PUBLIC_KEY = "X448 PUBLIC KEY"

Functions 6

private fnint base64CharValue(char c) pure @safe nothrowReturns the 6-bit value for a valid Base64 character, or -1 if invalid.
private fnsize_t findStr(string haystack, string needle, size_t start = 0) pure @safe nothrowFinds the first occurrence of `needle` in `haystack` starting at `start`. Returns the index, or `size_t.max` if not found.
fnstring base64Encode(const(ubyte)[] data) pure @safeEncodes raw bytes to a Base64 string (RFC 4648).
fnubyte[] base64Decode(string encoded) @safeDecodes a Base64 string to raw bytes.
fnstring pemEncode(string label, const(ubyte)[] derData) @safeEncodes raw DER bytes into PEM format.
fnPemBlock pemDecode(string pem) @safeDecodes a PEM-encoded string into its label and DER bytes.

Variables 1

private enumvarBASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

Standard Base64 alphabet (RFC 4648, Table 1).