Skip to content
iBlockSpam
SPF, DKIM & DMARC

What is DKIM, and how does a DKIM signature work?

By iBlockSpam Team How we check our guides Updated 10 min read 7 sources
Short answer

DKIM (DomainKeys Identified Mail) adds a cryptographic signature to each message. The sending domain signs selected headers and the body with a private key and publishes the public key in DNS at selector._domainkey.domain. Receivers fetch that key and check the signature. A pass proves the signing domain handled the message and the signed parts weren't changed.

DKIM is the email authentication method that survives the journey. Where SPF checks the server a message came from, DKIM signs the message itself, so the proof travels with it through relays and most forwarding. This guide explains what a signature contains, how receivers verify it, how keys and selectors work, and what breaks it. It's also the hub for our DKIM guides.

What is DKIM?

DKIM stands for DomainKeys Identified Mail. It's defined in RFC 6376, a Standards Track document from September 2011. The RFC says DKIM "permits a person, role, or organization to claim some responsibility for a message by associating a domain name with the message."

It works with a key pair:

  • Your mail platform holds a private key and uses it to sign each outgoing message.
  • The matching public key is published in DNS under your domain.
  • The receiver reads the signature, fetches the public key and checks that the two match.

Three things DKIM is not:

  • Not encryption. The message stays readable. DKIM proves origin and integrity only.
  • Not a From check. The signing domain can be any domain. Tying it to the visible From address is DMARC's job.
  • Not a reason to reject on its own. RFC 6376 section 6.3 says receivers "SHOULD NOT" decide acceptability based only on a missing or unverifiable signature, because "such rejection would cause severe interoperability problems."

How does DKIM signing work?

When your server sends a message, it:

  1. Picks the headers to sign and lists them in h=. The From: header "MUST be signed" (RFC 6376 section 5.4).
  2. Canonicalizes the headers and body: it normalizes them by the chosen rules so small, harmless changes in transit don't break the signature.
  3. Hashes the body and puts the result in bh=.
  4. Hashes the signed headers, including the new DKIM-Signature header itself with an empty b=, and signs that hash with the private key.
  5. Writes the signature into b= and adds the DKIM-Signature header to the top of the message.

A signature looks like this (shortened):

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=s202610;
  h=from:to:subject:date:message-id; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
  b=AuUoFEfDxTDkHlLXSZEpZj79LICEps6eda7W3deTVFOk4yAUoqOB...
Tag Meaning Required?
v= Version, always 1 Yes
a= Algorithm: rsa-sha256, or ed25519-sha256 (RFC 8463) Yes
d= Signing domain (the SDID). DMARC checks this for alignment Yes
s= Selector: which key under d= to fetch Yes
h= Signed header fields, in order Yes
bh= Hash of the canonicalized body Yes
b= The signature itself Yes
c= Canonicalization, header/body. Default simple/simple No
t=, x= Signing time and expiry No (x= is recommended)
l= Body length signed. Leaves later text unsigned; avoid No
i= Agent or user identifier; defaults to @ plus d= No

How does a receiver verify a DKIM signature?

  1. Read the DKIM-Signature header and check the required tags.
  2. Fetch the public key with a DNS TXT query for <s>._domainkey.<d>, for example s202610._domainkey.example.com.
  3. Recompute the body hash with the same canonicalization and compare it with bh=. A mismatch is the familiar "body hash did not verify" error.
  4. Verify b= against the signed headers using the public key.
  5. Record the result, for example dkim=pass header.d=example.com in Authentication-Results.

A message can carry several signatures, from the sender, an email service and a mailing list. A broken signature doesn't make a message worse than an unsigned one: RFC 6376 says a verifier "SHOULD NOT treat a message that has one or more bad signatures and no good signatures differently from a message with no signature at all."

What is DKIM canonicalization?

Mail gets lightly rewritten in transit: headers re-wrapped, trailing spaces trimmed. Canonicalization decides how much of that a signature tolerates. RFC 6376 section 3.4 defines two algorithms each for headers and body, written as c=header/body.

Algorithm Headers Body
simple No change at all; any edit breaks it Only trailing empty lines are ignored
relaxed Lowercases names, unfolds lines, collapses whitespace Collapses and trims whitespace in lines

The RFC says relaxed "tolerates common modifications such as whitespace replacement and header field line rewrapping." If c= is missing, simple/simple applies. Neither mode survives real content changes, such as a footer added by a mailing list or a disclaimer from a gateway.

What are DKIM selectors and DNS keys?

A selector names one key among several for the same domain. RFC 6376 section 3.1 introduces them "to support multiple concurrent public keys per signing domain." That's what lets each sending service have its own key, and lets you replace a key without downtime.

The key lives at <selector>._domainkey.<domain>:

s202610._domainkey.example.com.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."
Key tag Meaning
v=DKIM1 Version; recommended, and first if present
k= Key type: rsa (default) or ed25519
p= Public key, base64. An empty p= means the key is revoked
t=y Testing mode: receivers must treat mail like unsigned mail
h=, s= Optional limits on hash algorithms and service type

Providers differ in how they publish keys. Microsoft 365 uses two CNAME records, selector1 and selector2, that point to keys Microsoft hosts and rotates. Google Workspace has you publish one TXT record, by default at google._domainkey (Google). Our DKIM records by provider pages list the records for common services, and how to find a DKIM selector shows how to read one from a message.

How long should a DKIM key be?

RFC 8301 updated DKIM's crypto rules in 2018:

Rule RFC 8301 wording
Algorithm Signers "MUST sign using rsa-sha256"; "rsa-sha1 MUST NOT be used for signing or verifying"
Minimum RSA key Signers "MUST use RSA keys of at least 1024 bits"
Recommended RSA key Signers "SHOULD use RSA keys of at least 2048 bits"
Verifiers Must handle 1024 to 4096 bits, and "MUST NOT consider signatures using RSA keys of less than 1024 bits as valid"

Use 2048-bit RSA. The catch is DNS: a 2048-bit public key is too long for one 255-character TXT string, so it's stored as several strings that receivers join back together. Most DNS hosts handle this; if yours truncates the key, the signature fails.

What about Ed25519?

RFC 8463 adds the Ed25519-SHA256 algorithm, which "has much shorter keys than RSA for similar levels of security." Its key record uses k=ed25519, and the base64 public key is only 44 characters, so it fits in one TXT string. The RFC says verifiers MUST implement it, but large mailbox providers don't document whether they do, and Microsoft 365 documents only RSA keys (1024 or 2048 bits) for its DKIM signing. RFC 8463 section 6 gives the safe path: sign with both algorithms, each under its own selector.

How does DKIM relate to DMARC?

DMARC (RFC 9989) passes a message when SPF or DKIM passes for a domain that aligns with the From domain. For DKIM, the domain that counts is d=. RFC 9989 explains why alignment is needed: "a message can bear a valid signature from any domain, even one used by a bad actor."

So a pass isn't always a useful pass. If your newsletter tool signs with d=vendor-mail.net, DKIM passes, but DMARC for example.com gets nothing from it. Turn on custom-domain signing in each service so d= is your domain or a subdomain of it.

DKIM matters more for DMARC than SPF does, because it generally survives forwarding. RFC 9989 section 7.4 says forwarded mail "will most likely fail SPF checks" while "DKIM signatures will generally remain valid", and says domains publishing p=reject "MUST apply valid DKIM signatures to their messages." For the full picture, see what DMARC is and SPF vs DKIM vs DMARC.

What breaks DKIM?

Symptom in headers Likely cause Fix
body hash did not verify Body changed after signing: list footers, disclaimers, gateways, re-encoding Sign after the last change, or have the modifier re-sign
signature did not verify A signed header changed, or the wrong key is published Compare the published key with the signing key
no key for signature Selector record missing, typo, or not yet in DNS Publish the record at <s>._domainkey.<d>
Key syntax error TXT key truncated or split wrongly Re-publish the full key as joined strings
key revoked p= is empty Sign with the current selector
Pass, but DMARC fails d= is the vendor's domain Turn on custom-domain signing

The first row is the most common. Our guide to DKIM "body hash did not verify" covers each failure in detail.

How often should you rotate DKIM keys?

M3AAWG's key rotation guidance says "DKIM keys should be rotated at least every six months"; its April 2018 revision relaxed the earlier quarterly cycle. Selectors make it painless, as RFC 6376 section 3.1 describes: publish the new key under a new selector, switch signing to it, and keep the old public key published while mail signed with it may still be in transit. Then revoke the old one.

Microsoft 365 rotates between its two selectors when you trigger it, and Microsoft Learn documents the steps. The full procedure for other platforms is in DKIM key rotation.

How do I set up DKIM?

  1. List every service that sends as your domain, as you would for SPF.
  2. Turn on custom-domain signing in each one. Most services generate the key and show you a TXT or CNAME record to publish. Our DKIM setup guide for Microsoft 365 and Google Workspace covers the two big platforms step by step.
  3. Run your own mail server? Create a 2048-bit key pair with the DKIM Key Generator, which makes the key in your browser, and configure your server to sign with it.
  4. Publish the record at your DNS host, then check it with the DKIM Checker.
  5. Send a test message to an outside mailbox and confirm dkim=pass with your domain in header.d, using the Email Header Analyzer.
  6. Publish DMARC so receivers act on the result.

Our DKIM guides

If you need to... Read
Set up DKIM on Microsoft 365 or Google Workspace DKIM setup guide
Find the records for a specific provider DKIM records by provider
Find which selector a domain uses How to find a DKIM selector
Fix a failing signature DKIM body hash did not verify
Replace keys safely DKIM key rotation

Next steps

  1. Check your selectors and key strength with the DKIM Checker.
  2. Confirm every sending service signs with your domain in d=, not the vendor's.
  3. Replace any 1024-bit key with a 2048-bit one at the next rotation, and put rotation on the calendar.
  4. Once DKIM passes everywhere, move your DMARC policy toward enforcement; check it with the DMARC Checker.

DKIM protects your domain in other people's inboxes. For the mail arriving at yours, an inbound filter such as iBlockSpam checks each sender's authentication alongside spam and phishing signals; see how it works.

If apps or devices send mail through iBlockSpam, its outbound relay DKIM-signs those messages, with 500 relay messages per domain per month included.

Browse our other SPF, DKIM and DMARC guides.

Frequently asked questions

What does DKIM stand for?

DomainKeys Identified Mail. The current specification is RFC 6376, published in September 2011, which replaced RFCs 4871 and 5672. Later updates added stricter key rules (RFC 8301) and a second signing algorithm, Ed25519 (RFC 8463). Together they define how signatures are created, published and verified.

Does DKIM encrypt my email?

No. DKIM signs a message; it doesn't hide it. Anyone handling the message can still read it. The signature only lets a receiver check which domain took responsibility for the message and whether the signed headers and body changed in transit. Encryption in transit is a separate job for TLS.

Where is the DKIM public key published?

In DNS, as a TXT record at the selector name under _domainkey, for example s1._domainkey.example.com. The selector comes from the s= tag of the signature and the domain from d=. Some providers, including Microsoft 365, ask you to publish a CNAME there that points to a key they host.

Can a message pass DKIM and still fail DMARC?

Yes. DMARC needs a DKIM pass for a domain that aligns with the visible From domain. If your email platform signs with its own domain, such as a vendor's sending domain, DKIM passes for that domain but doesn't count for yours. Set up custom-domain signing so d= matches your domain.

Should I use Ed25519 for DKIM?

Only as a second signature next to RSA. RFC 8463 says verifiers must implement Ed25519, but large mailbox providers don't document whether they verify it, and Microsoft 365 documents only RSA keys (1024 or 2048 bits) for its DKIM signing. RFC 8463 describes signing with both algorithms under separate selectors, so receivers that can't verify Ed25519 still get a valid RSA signature.

Sources

  1. RFC 6376: DomainKeys Identified Mail (DKIM) Signatures
  2. RFC 8301: Cryptographic Algorithm and Key Usage Update to DKIM
  3. RFC 8463: A New Cryptographic Signature Method for DKIM (Ed25519)
  4. RFC 9989: Domain-Based Message Authentication, Reporting, and Conformance (DMARC)
  5. Microsoft Learn: How to use DKIM for email in your custom domain
  6. Google Workspace Admin Help: Set up DKIM
  7. M3AAWG: DKIM Key Rotation Best Common Practices (revised April 2018)

See how your domain measures up

Run a free Email Health Check: MX, SPF, DKIM, DMARC and transport security in one scan, with the raw records shown. No sign-up.

Keep reading