DKIM Explained: How Email Cryptographic Signatures Work

TL;DR

  • DKIM (DomainKeys Identified Mail) adds a cryptographic digital signature to every outgoing email. This signature allows receiving servers to verify that the email was sent by an authorised server and has not been tampered with in transit.
  • DKIM uses public-key cryptography. The sending server signs the email with a private key, and receiving servers verify the signature using a public key published in DNS.
  • DKIM works through email forwarding because the signature travels with the email, unlike SPF which breaks with forwarding.
  • DKIM is not a complete solution on its own. It does not prevent spoofing of the header From address without DMARC alignment.
  • Use RSA 2048-bit keys as the minimum for 2026. 1024-bit keys are considered weak and are rejected by some providers. Ed25519 is an emerging alternative but should only be used with dual-signing alongside RSA-2048.

What Is DKIM?

DKIM (DomainKeys Identified Mail) is a domain-level email authentication framework defined by RFC 6376 (published in 2011, with RFC 8301 updating cryptographic requirements in 2018). It uses public-key cryptography to bind an email’s content and critical headers to a domain identity.

The problem DKIM solves: Email can be tampered with in transit-headers can be altered, content can be modified, and senders can be spoofed. DKIM provides a way for receiving servers to verify that an email claiming to come from your domain actually did, and that it hasn’t been changed since it was signed.

How DKIM differs from SPF:

  • SPF checks the envelope sender (Return‑Path) to verify the sending IP is authorised.
  • DKIM checks the message content and headers using a cryptographic signature that travels with the email-so it works through forwarding.

How DKIM Works Step by Step

How DKIM works step by step. The sender signs the email with a private key, adds the DKIM-Signature header, and sends it to the recipient, who retrieves the public key from DNS and verifies the signature.

Detailed breakdown:

  1. Email composition: The sending server prepares the email message.
  2. Hashing: The server creates cryptographic hashes of the message body and selected headers (e.g., From, To, Subject).
  3. Signing: The server signs the combined hash with its private key.
  4. Signature insertion: The signature is added to the email as a new DKIM-Signature header field.
  5. DNS lookup: The receiving server looks up the public key for the domain using the selector specified in the signature (e.g., selector1._domainkey.example.com).
  6. Verification: The receiving server uses the public key to verify the signature against the email content.
  7. Result: The verification returns either pass or fail.

DKIM Record Syntax

A DKIM record is a DNS TXT record that stores the public key. It is published under a selector name:

selector1._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC..."

Components

ComponentMeaning
selectorIdentifies the specific key pair (allows key rotation)
_domainkeyFixed part of the record (required for DKIM)
v=DKIM1Version identifier (must be “DKIM1”)
k=rsaKey type (RSA is the standard; Ed25519 is emerging)
p=…Public key (base64 encoded)

Important: The public key is stored in the DNS TXT record, while the private key remains securely on the sending server. A common mistake is publishing the private key instead of the public key.

DKIM Headers in Email

The DKIM-Signature header is added to every signed email:

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=example.com; s=selector1; t=1690000000;
 bh=...; h=from:to:subject; b=...

Components

FieldMeaning
v=1DKIM version
a=rsa-sha256Signing algorithm (RSA with SHA-256)
c=relaxed/relaxedCanonicalisation method (header/body)
d=example.comSigning domain
s=selector1Selector name (points to DNS record)
t=1690000000Timestamp (UNIX epoch)
bh=...Body hash
h=from:to:subjectHeaders included in the signature
b=...Digital signature

Canonicalisation

DKIM supports two canonicalisation methods:

  • simple – No changes tolerated. The message must be byte‑for‑byte identical for verification to pass.
  • relaxed – Allows minor modifications (whitespace changes, line wrapping) that often occur during email transit.

The format is header/body (e.g., relaxed/relaxed). For most use cases, relaxed/relaxed is recommended because it tolerates common modifications while maintaining security.

The following header fields should be included in the signature if present:

  • From – REQUIRED in all signatures
  • Sender
  • Reply‑To
  • Subject
  • Date
  • Message‑ID

DKIM Selectors

A selector is a name that identifies a specific DKIM key pair for a domain. It allows a domain to have multiple keys active simultaneously, which is essential for key rotation.

Why Selectors Matter

  • Key identification: The selector tells receiving servers which public key to use for a given email.
  • Zero‑downtime rotation: You can publish a new key under a new selector while the old selector remains active.
  • Multiple senders: Different sending services (e.g., marketing email, transactional email) can each have their own selector.

Selector Naming

Choose names that are:

  • Meaningful for forensic analysis (e.g., google_2026, mailchimp_q3)
  • Sufficiently random so keys cannot be easily guessed
  • DNS‑compatible (some DNS providers do not allow underscores in record names)

DKIM Key Rotation

Key rotation is the process of replacing a DKIM private key with a new one to maintain security.

Why Key Rotation Matters

  • Compromised keys: If a private key is leaked, attackers can sign fraudulent emails.
  • Cryptographic obsolescence: Older algorithms and key lengths become weaker over time.
  • Compliance: Some standards require periodic key rotation.
  • Every 6 to 12 months is the widely recommended interval.
  • Large organisations should rotate every 3 to 6 months.
  • RSA‑1024 keys should be rotated immediately-they are now considered weak.

Zero‑Downtime Rotation Process

  1. Generate a new key pair with a new selector name (e.g., selector2).
  2. Publish the new public key in DNS under the new selector.
  3. Keep both selectors active during the transition.
  4. Update all sending systems to sign with the new key.
  5. Wait for DNS propagation (48–72 hours).
  6. Verify DMARC alignment still passes.
  7. Remove the old selector from DNS after the grace period.

Common DKIM Mistakes

MistakeWhy It’s a ProblemFix
Syntax errors (quoting, semicolons, base64)Invalid DNS record format; verification failsValidate the record with a DKIM checker before publishing
Selector/domain mismatchReceiving server looks up the wrong keyEnsure the selector in DNS matches the one in the DKIM-Signature header
Incorrect key splittingSome DNS providers have 255‑character TXT record limits; splitting incorrectly breaks the recordUse proper quoting for multi‑line TXT records; some providers automatically handle splitting
Weak or outdated keys (1024‑bit RSA)1024‑bit keys are considered weak and rejected by some providersUse RSA‑2048 minimum
Private key exposedAttackers can sign fraudulent emailsKeep the private key secure; never share it
Not signing critical headersModification of unsigned headers is undetectableAlways sign the From header (REQUIRED) and other key headers
DNS propagation delayVerification fails until DNS propagatesWait 24‑48 hours before testing, and set appropriate TTLs
Using a CNAME instead of a TXT recordDKIM lookups expect TXT records; CNAMEs may cause resolution issuesAlways use a TXT record for DKIM
Incorrect record name formatRecord name must end with ._domainkey.yourdomain.comUse the exact format: selector._domainkey.example.com

Testing DKIM

Online Tools

ToolPurpose
MXToolbox DKIM CheckValidates DKIM record existence and syntax
DKIM Core ValidatorComprehensive DKIM signature verification
Google Admin ToolboxEmail header analyser

Command Line

dig TXT selector1._domainkey.example.com +short

Expected output:

"v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC..."

Email Header Inspection

In your email client, view the full headers and look for:

Authentication-Results: dkim=pass header.d=example.com;

A pass result means the DKIM signature was successfully verified.

DKIM Best Practices

  1. Use RSA 2048‑bit keys as the minimum. 1024‑bit keys are now considered weak and are rejected by some providers. 2048‑bit RSA is the recommended default for 2026, meeting RFC 8301, NIST specifications, and Google/Yahoo bulk sender requirements.
  2. Sign key email headers. Always include the From header (REQUIRED), and include Sender, Reply‑To, Subject, Date, and Message‑ID when present.
  3. Rotate keys regularly. Every 6 to 12 months using a parallel selector.
  4. Test after configuration. Send test emails and verify the Authentication-Results header shows dkim=pass.
  5. Monitor DKIM results. Use DMARC aggregate reports to see whether your DKIM signatures are being verified successfully.
  6. Use relaxed/relaxed canonicalisation. This tolerates minor modifications during transit while maintaining security.
  7. Set appropriate TTLs. Use a TTL of 300–3600 seconds to allow for quick changes during key rotation.
  8. Maintain a selector inventory. For organisations using multiple sending services, keep a centralised list of active selectors, rotation schedules, and signing domains.

Ed25519: The Emerging Alternative

Ed25519 offers equivalent or better security than RSA‑2048 with just 256‑bit keys-an 8× reduction in DNS record size. Signature verification is also 10‑20× faster than RSA‑2048.

However: Not all receivers can verify Ed25519 signatures yet.

Recommendation for 2026: Use RSA‑2048 as your default. If you want to use Ed25519, implement it as a dual signature alongside RSA‑2048-never use Ed25519 alone.

How DKIM Enables DMARC

DKIM is essential for DMARC because:

  • DMARC requires either SPF or DKIM to pass.
  • DKIM alignment (the domain in the d= tag matching the domain in the header From) is required for DMARC to pass.
  • DKIM works through email forwarding, making it more reliable than SPF for DMARC alignment in forwarded mail.

Without DKIM, DMARC enforcement is less effective because SPF fails when email is forwarded.

Key Takeaways

  • DKIM provides cryptographic verification that an email came from an authorised server and has not been tampered with.
  • DKIM works through email forwarding because the signature travels with the email, unlike SPF.
  • DKIM uses public-key cryptography with private keys on sending servers and public keys published in DNS.
  • Use RSA 2048‑bit keys as the minimum for 2026. 1024‑bit keys are considered weak.
  • Rotate DKIM keys every 6 to 12 months using a parallel selector for zero‑downtime transitions.
  • DKIM is not a complete solution without DMARC alignment to verify the header From address.
  • Ed25519 is emerging but should only be used with dual-signing alongside RSA‑2048.

Conclusion

DKIM (DomainKeys Identified Mail) is a critical component of modern email authentication. By adding a cryptographic signature to every outgoing email, DKIM allows receiving servers to verify that the email genuinely came from your domain and has not been tampered with in transit.

Unlike SPF, DKIM works through email forwarding because the signature travels with the email. This makes DKIM essential for DMARC enforcement, particularly when email is forwarded.

For 2026, RSA 2048‑bit keys are the recommended default, meeting RFC 8301 and major provider requirements. Keys should be rotated every 6 to 12 months using a parallel selector to avoid downtime. Ed25519 is an emerging alternative but should only be used with dual-signing alongside RSA‑2048.

DKIM is not a complete solution on its own. It must be combined with SPF (to authorise sending IPs) and DMARC (to enforce policies and verify header From alignment) for comprehensive email authentication.

Resources

Need help setting up email authentication for your domain? Playful Sparkle has been engineering digital products since 2004, offering Web Development, App Development, and security consulting services. Our team can help you configure SPF, DKIM, DMARC, and BIMI for your domain. Contact us to discuss how we can help you secure your email.

Was this helpful - Post
Zsolt Oroszlány

Zsolt Oroszlány

Founder & Chief Creative Officer of Playful Sparkle since 2004, combining business leadership, digital strategy, design, and software engineering to help organizations build effective digital solutions. Regularly publishes insights on web development, SEO, design, and emerging technologies.