Learn
What is DKIM? DKIM signing and keys explained
What is DKIM? A signature that ties an email to a domain, checked with a public key in DNS. How signing works, a sample record and common mistakes.
What it is
What is DKIM? DKIM (DomainKeys Identified Mail) is an email authentication standard that lets a domain sign each message with a private key, so the receiving server can check the signature with a public key published in DNS. The signature is tied to a domain name and carried in a message header.
A valid signature shows that a domain took responsibility for the message and that the signed content has not changed since signing. DKIM does not encrypt anything. A failed check does not force a rejection by itself. The signing domain can also differ from the domain in the From address.
How DKIM signing works
- The sending system hashes the message body, which means it computes a short fingerprint of it. The result goes in the
bh=tag of a newDKIM-Signatureheader. - It signs the header fields listed in
h=, plusDKIM-Signatureitself, with the private key. The result goes inb=. - The receiving server reads the signing domain in
d=and the selector ins=, which names the key to use. It fetches the public key from a DNS TXT record at<selector>._domainkey.<domain>. - It recomputes the hashes, compares the body hash with
bh=and verifiesb=with the public key. A receiver that adds anAuthentication-Resultsheader recordsdkim=passfor a signature that verifies and that its local policy accepts.
What is a DKIM key?
A DKIM key is one half of a key pair. The private key stays with the system that signs your mail. The public key sits in DNS for any receiver to fetch.
A domain can publish several keys, one per selector, so each server or provider can sign with its own. In Google Workspace, the default selector is google, published as a TXT record. For a custom domain, Microsoft 365 uses selector1._domainkey and selector2._domainkey as CNAME records (DNS aliases).
RFC 8301 rules out rsa-sha1, requires RSA keys of at least 1024 bits and advises at least 2048. To create a key, see how to set up DKIM.
DKIM and DMARC
DKIM is one of the two mechanisms behind DMARC, the policy check on the From address. DMARC counts a DKIM pass only when the d= domain aligns with the From domain. In the default relaxed mode, d=example.com aligns with mail from news.example.com.
Example
This signature is illustrative. The selector brisbane comes from the example in RFC 6376, and long values are shortened.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=brisbane;
h=from:to:subject:date; bh=2jUSOH9NhtVGCQWN...; b=AuUoFEfDxTDkHlLXSZEp...
v=1anda=rsa-sha256: the signature version and the signing algorithm.c=relaxed/relaxed: how the header and body are normalized before hashing, a step called canonicalization.relaxedtolerates common changes such as line rewrapping in headers.simpletolerates almost none.d=example.comands=brisbane: the domain that takes responsibility and the selector.h=: the signed header fields.Frommust be one of them.bh=andb=: the body hash and the signature.
In this example, the public key would sit in a TXT record at brisbane._domainkey.example.com:
v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...
p= holds the public key, shortened here. An empty p= means the key was revoked. To read a real record, use the DKIM Checker.
Common mistakes
- Assuming a DKIM pass means DMARC passes. A service can sign with its own domain in
d=. The signature verifies but does not align with your From domain. Where the service allows it, have it sign with your domain. - Publishing the key at the wrong name. Microsoft notes that most DNS providers add your domain to the host name automatically. Typing the full name then creates
brisbane._domainkey.example.com.example.com. At those providers, enter onlybrisbane._domainkey. - Cutting a long key short. Google warns that a 2048-bit key cannot go in as one string where the limit is 255 characters. Split it into quoted strings in the same record, and keep one TXT record per selector.
- Reusing a selector for a new key. RFC 6376 advises new selectors for new keys. Publish the new key under a new selector, confirm it appears in DNS, then switch the signer. Caution: keep the old key in DNS until mail signed with it has reached its destination. If you remove it early, that mail can fail DKIM. If your DMARC policy is
p=quarantineorp=reject, receivers may then junk or refuse it unless SPF passes and aligns. - Changing the message after signing. Mailing lists that tag the subject or add a footer can invalidate the signature, as RFC 6377 explains. A changed body shows up as body hash did not verify.