DKIM Signing
Cryptographically signing messages.
DKIM Signing is a free Cyber Security Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cyber Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What DKIM Provides
DKIM (DomainKeys Identified Mail) attaches a cryptographic signature to outgoing email. A receiver can verify that signature to confirm two things:
- The message was genuinely authorized by the signing domain
- The signed content was not altered in transit
Where SPF authorizes servers, DKIM authenticates the message itself, and that signature survives forwarding.
Public Key Cryptography Basics
DKIM relies on asymmetric cryptography. The domain owner holds a key pair:
- The private key stays secret on the sending mail server and is used to sign
- The public key is published in DNS and is used by anyone to verify
Because only the holder of the private key can produce a valid signature, a successful verification proves the message came from the legitimate domain.
The Signing Process
When the sending server dispatches a message, it computes a signature over selected headers and the body, then adds a DKIM-Signature header.
Steps on the sender side:
1. Select headers to sign (From, Subject, Date, ...)
2. Hash the message body
3. Build the DKIM-Signature header with those fields
4. Sign the hash with the private key
5. Attach the signature to the outgoing messageAnatomy of a DKIM-Signature Header
The DKIM-Signature header carries the parameters a receiver needs to verify:
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=company.com; domain that signed
s=mail2024; selector (which key)
h=from:subject:date; signed headers
bh=base64bodyhash; body hash
b=base64signature the signature itselfThe Selector and Public Key in DNS
The selector (the s= tag) tells receivers which public key to fetch. The key lives at a predictable DNS location:
Location: <selector>._domainkey.<domain>
Example DNS TXT record:
mail2024._domainkey.company.com. IN TXT \
"v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBA..."
p = the base64-encoded public keyThe Verification Process
On receipt, the verifying server reverses the process:
- Read the
d=domain ands=selector from the DKIM-Signature - Fetch the public key from
selector._domainkey.domainin DNS - Recompute the body hash and header hash
- Use the public key to verify the signature matches
If the signature is valid, DKIM passes. If the message was modified or signed with the wrong key, it fails.
Body Hash Detects Tampering
The bh (body hash) field is what makes DKIM tamper-evident. The sender hashes the body and includes that hash in the signed data.
If anyone alters the message body in transit, the receiver's recomputed hash will not match the signed bh, and verification fails. This is how DKIM provides integrity, not just origin authentication.
Canonicalization
Mail servers along the way often make tiny, harmless changes, rewrapping lines or adjusting whitespace. To prevent these from breaking valid signatures, DKIM uses canonicalization (the c= tag).
- simple — strict; almost any change breaks the signature
- relaxed — tolerant of whitespace and header-case changes
Most deployments use relaxed/relaxed for reliability across diverse mail infrastructure.
Selectors Enable Key Rotation
Selectors are not just labels, they enable safe key rotation. You should periodically replace DKIM keys to limit exposure if one leaks.
Rotation process:
- Generate a new key pair with a new selector (e.g.
mail2025) - Publish the new public key in DNS
- Switch the signer to use the new selector
- Leave the old selector in DNS until in-flight mail is delivered, then remove it
Using a fresh selector avoids a gap where signatures cannot be verified.
DKIM Survives Forwarding
Unlike SPF, DKIM survives forwarding. The signature travels with the message, so as long as the signed headers and body are not modified, a forwarded message still verifies.
This complements SPF's weakness perfectly. When a message is forwarded, SPF may fail because the connecting IP changed, but DKIM can still pass, allowing DMARC to accept the legitimate mail.
DKIM Limitations
DKIM is powerful but not complete on its own:
- It proves a domain signed the message, but does not enforce that the signing domain matches the visible From header, that is DMARC alignment
- An attacker can sign mail with their own domain's valid DKIM key
- A leaked private key lets an attacker forge valid signatures until the key is rotated out
DKIM must be combined with DMARC to be meaningful against spoofing.
Quick Check
Test your understanding of DKIM.
Recap
You learned how DKIM signs messages:
- DKIM attaches a cryptographic signature proving origin and integrity
- A private key signs on the server; the public key is published in DNS under a selector
- The body hash detects tampering; canonicalization tolerates harmless changes
- Selectors enable safe key rotation, and DKIM survives forwarding where SPF fails
- DKIM still needs DMARC alignment to tie the signature to the visible From
Next, you will tie SPF and DKIM together with DMARC policy and reporting.
Frequently asked questions
Is the “DKIM Signing” lesson free?
Yes — the full text of “DKIM Signing” is free to read here on the web, and the Cyber Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cyber Security Academy course, upgrade to CoddyKit PRO.
What will I learn in “DKIM Signing”?
Cryptographically signing messages. You practise Cyber Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cyber Security Academy?
No prior experience is required. Cyber Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “DKIM Signing” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cyber Security Academy lesson?
Yes. Every Cyber Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.