Skip to content
DKIM — Signing Messages
step 1/5

Reading — step 1 of 5

Read

~1 min readAnti-Spam & DKIM

DKIM — Signing Messages

DKIM (RFC 6376) cryptographically signs email so the recipient can verify the sender's domain didn't tamper with it in transit.

Sender (typically the outgoing MTA) computes a signature over headers + body using a private key. The signature goes in a DKIM-Signature: header:

DKIM-Signature: v=1; a=rsa-sha256; d=example.com; s=mail;
    c=relaxed/relaxed; q=dns/txt;
    h=from:to:subject:date;
    bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
    b=ABC123signedhash...

Fields:

  • v: version.
  • a: algorithm (rsa-sha256, ed25519-sha256).
  • d: signing domain.
  • s: selector (sub-key identifier).
  • c: canonicalization method for headers/body.
  • h: list of headers that were signed.
  • bh: hash of canonicalized body.
  • b: signature over the canonicalized headers (including the DKIM-Signature header itself with b= empty during sign).

Public key in DNS:

mail._domainkey.example.com.  IN  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."

Verifier (recipient MTA):

  1. Parse DKIM-Signature header.
  2. Fetch public key from <selector>._domainkey.<d> DNS TXT.
  3. Canonicalize body, compute hash, compare to bh. Mismatch → fail.
  4. Canonicalize specified headers + the DKIM-Signature (with b empty), verify signature against public key. Mismatch → fail.

Canonicalization:

  • simple: barely modified (CRLF normalization).
  • relaxed: lowercase header names, collapse whitespace, strip trailing whitespace. More robust to mailing list / forwarder mangling.

Multiple signatures: a message can have several DKIM-Signature headers. ARC (RFC 8617) extends DKIM for legitimate forwarders.

Selectors enable key rotation: publish new selector + key, sign with new, revoke old after grace period.

DKIM is widely deployed. Failures often = mailing list re-formats body (modifies headers / footers / re-encodes), breaking signature.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…