Karta. Auth. DKIM. Key
(Karta v1.0.0)
A DKIM signing key: RSA (2048, 3072 or 4096 bits) or Ed25519 (RFC 8463).
generate/2makes a new key;to_pem/1andfrom_pem/1convert to and from PKCS #8 PEM, the form stored (encrypted, seeKarta.Auth.DKIM.EncryptedKey) and exported.dns_record/1is the public key record to publish at<selector>._domainkey.<domain>;dns_strings/1splits it into the 255-octet character-strings of a TXT record.sign/2signs the header data of a DKIM signature.
RSA keys under 2048 bits can be read (to inspect or replace an old key)
but Karta.Auth.DKIM.Signer refuses to sign with them (RFC 8301 §3.2
recommends 2048 bits).
Summary
Types
private and public are the :public_key RSA records for RSA keys,
and the 32-byte seed and public key for Ed25519.
Functions
The DKIM key record (RFC 6376 §3.6.1, RFC 8463 §4): v=DKIM1; k=rsa; p=<SubjectPublicKeyInfo> or v=DKIM1; k=ed25519; p=<the 32-octet key>,
base64.
dns_record/1 cut into character-strings of at most 255 octets, for a TXT record.
Reads a PEM private key: PKCS #8 (RSA or Ed25519) or PKCS #1
(-----BEGIN RSA PRIVATE KEY-----). RSA keys must have at least 1024
bits. Anything else is {:error, :invalid_key}.
Generates an RSA key of 2048, 3072 or 4096 bits, or an Ed25519 key.
Signs the canonicalised header data of a DKIM signature: RSASSA-PKCS1-v1_5 with SHA-256, or Ed25519 over the SHA-256 hash of the data (RFC 8463 §3).
The key as PKCS #8 PEM (-----BEGIN PRIVATE KEY-----).
Types
@type algorithm() :: :rsa | :ed25519
@type t() :: %Karta.Auth.DKIM.Key{ algorithm: algorithm(), bits: pos_integer(), private: term(), public: term() }
private and public are the :public_key RSA records for RSA keys,
and the 32-byte seed and public key for Ed25519.
Functions
The DKIM key record (RFC 6376 §3.6.1, RFC 8463 §4): v=DKIM1; k=rsa; p=<SubjectPublicKeyInfo> or v=DKIM1; k=ed25519; p=<the 32-octet key>,
base64.
dns_record/1 cut into character-strings of at most 255 octets, for a TXT record.
Reads a PEM private key: PKCS #8 (RSA or Ed25519) or PKCS #1
(-----BEGIN RSA PRIVATE KEY-----). RSA keys must have at least 1024
bits. Anything else is {:error, :invalid_key}.
@spec generate(algorithm(), pos_integer() | nil) :: t()
Generates an RSA key of 2048, 3072 or 4096 bits, or an Ed25519 key.
Signs the canonicalised header data of a DKIM signature: RSASSA-PKCS1-v1_5 with SHA-256, or Ed25519 over the SHA-256 hash of the data (RFC 8463 §3).
The key as PKCS #8 PEM (-----BEGIN PRIVATE KEY-----).