Import std.crypto.pem
std.crypto.pem
Key and Certificate, which read keys and X.509 certificates from PEM, the text between "-----BEGIN ...-----" and "-----END ...-----" lines that keys and certificates are kept in, over mbedTLS. A Key's Bytes are what its kind's Methods take, so a key read from PEM signs, verifies, or exchanges. RSA keys are of up to 8192 bits.
std/crypto/pem.fb
Types
KeyKind
enum
Public Enum KeyKind
What a Key is for, which says what its Bytes are.
-
An ECDSA P-256 key, for signing: a private key's 32 bytes, or a public key's 65.
-
An RSA key, for verifying signatures: its PKCS #1 DER.
-
An X25519 key, for key agreement: its 32 bytes.
-
An Ed25519 key, for signing: its 32 bytes.
Key
struct
Public Struct Key
A private or public key, as its kind's Methods take it: an ECDSA P-256 private key's 32 bytes or public key's 65; an RSA key's PKCS #1 DER, whose public one Rsa verifies with; and an X25519 or Ed25519 key's 32 bytes.
-
What kind of key it is.
-
Whether it's a private key, or a public one.
-
Its bytes, as its kind's Methods take them.
-
A key of
kind, private or public, ofbytes. -
The first key in
pem, whatever comes after it: a private one in PKCS #8 ("PRIVATE KEY"), SEC 1 ("EC PRIVATE KEY"), or PKCS #1 ("RSA PRIVATE KEY"), or a public one ("PUBLIC KEY", or "RSA PUBLIC KEY"). Throws a ParseError of SYNTAX whenpemhas no key, or one that doesn't read, and of WRONG_TYPE when it's encrypted, or of a kind there's no KeyKind for, like another curve's. -
The key as PEM, as OpenSSL writes it: a private one in PKCS #8, but an RSA one in PKCS #1 and a P-256 one in SEC 1, and a public one, RSA's too, in SubjectPublicKeyInfo. Panics when Bytes isn't a key of its Kind.
Certificate
struct
Public Struct Certificate
An X.509 certificate, read from PEM: who it's for and who signed it, as Python's ssl shows them, "C=NL, O=Example, CN=example.com", in the certificate's order, as UTF-8 text with RFC 4514's escapes; its serial number as hex bytes with colons between them; the UTC times it's valid from and to, as "2026-10-23T12:00:00Z"; its public key; and its DER. Checking that one certificate signed another, or that one is trusted, is TLS's.
-
Who it's for, like "C=NL, O=Example, CN=example.com".
-
Who signed it, as Subject says who it's for.
-
Its serial number, as hex bytes with colons between them.
-
The UTC time it's valid from, like "2026-10-23T12:00:00Z".
-
The UTC time it's valid until, like "2026-10-23T12:00:00Z".
-
Its public key, or Null when it's of a kind there's no KeyKind for.
-
Its DER bytes.
-
The first certificate in
pem. Throws a ParseError whenpemhas none, or one that doesn't read. -
Each certificate in
pem, in order, as a chain or a bundle of trusted ones has them. Throws a ParseError whenpemhas none, or one that doesn't read.
Report an issue with this page or with FutureBlitz on GitHub.