DKIM Explained: How Cryptographic Email Signing, Selectors, and Public Keys Work
DomainKeys Identified Mail (DKIM) is an email authentication method that attaches a cryptographic digital signature to outgoing emails to prove they came from your domain and were not altered in transit. Your mail server signs each message with a private key (DKIM-Signature). The public key of a DKIM record lives in your DNS at <selector>._domainkey so receivers verify it.
How Does DKIM Signing and Verification Work Step by Step?
DomainKeys Identified Mail (DKIM) allows a domain owner to take cryptographic responsibility for a message, proving that the email body and attachments were not tampered with in transit. The validation workflow operates across 7 sequential cryptographic steps split between the outbound sending mail server (Steps 1 to 3) and the inbound receiving mail server (Steps 4 to 7).
Mail transfer agents sign and verify messages through 7 sequential technical operations:
- Canonicalize the outbound email body and selected headers (From, To, Subject, Date, Message-ID) on the sending Mail Transfer Agent (MTA) using the normalization rule specified in
c=(such asrelaxed/relaxed). - Compute a SHA-256 cryptographic hash of the normalized message body (
bh=) and sign the selected headers plus theDKIM-Signatureheader fields using the domain's private RSA or Ed25519 key to generate the digital signature (b=). - Prepend the completed
DKIM-Signatureheader (for example,v=1; a=rsa-sha256; d=example.com; s=selector1; bh=...; b=...) to the message and transmit the email over SMTP. - Extract the signing domain (
d=example.com) and the selector (s=selector1) from the incomingDKIM-Signatureheader at the receiving mail server. - Query the authoritative DNS servers for the TXT resource record located at
<selector>._domainkey.<domain>(for example,selector1._domainkey.example.com) to retrieve the sender's public key (p=). - Verify the cryptographic header signature (
b=) against the canonicalized headers using the public key, and recalculate the SHA-256 hash of the received message body locally. - Record
dkim=passin theAuthentication-Resultsheader if the header signature validates and the recalculated body hash (bh=) matches byte-for-byte, or returndkim=failif any signed header or body text was altered in transit.
The asymmetric cryptographic architecture of DKIM establishes message integrity and authenticity without relying on centralized certificate authorities. Administrators can inspect signature execution in How DKIM Works, test public keys with the DKIM Record Checker, or dissect raw authentication chains in the Email Header Analyzer.
What Is the Difference Between a DKIM-Signature Header and a DKIM DNS Record?
DKIM splits its tag-value syntax across 2 separate locations: the DKIM-Signature header attached to every email (v=1) and the public key TXT record published once in DNS (v=DKIM1). The table below compares the core tags found in the email header against the tags published in the DNS zone.
DKIM-Signature Header Example (Inside Message Headers):
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=example.com; s=google; t=1761680000;
h=from:to:subject:date:message-id;
bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
b=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA... DKIM Public Key DNS TXT Record Example (Published in DNS):
google._domainkey.example.com. 3600 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..." | Location | Tag | Meaning |
|---|---|---|
| Email header | v=1 | DKIM signature version |
| Email header | a=rsa-sha256 | Signing algorithm |
| Email header | d=example.com | Signing domain (the d= tag) |
| Email header | s=selector1 | Selector used for the DNS lookup |
| Email header | bh= | Body hash |
| Email header | b= | Signature data |
| DNS TXT record | v=DKIM1 | Record version |
| DNS TXT record | k=rsa | Key type |
| DNS TXT record | p= | Public key material (empty p= means revoked) |
| DNS TXT record | t=y | Testing mode flag |
The DKIM standard establishes distinct parsing rules across these two artifacts: in the message header, the v=1 tag is mandatory, whereas in the DNS TXT record, v=DKIM1 is optional because p= serves as the only mandatory DNS tag. Publishing a DNS TXT record with an empty public key tag (such as v=DKIM1; p=) constitutes the official key revocation method, signaling to receiving mail servers that the private key is decommissioned and any future signatures under that selector fail. Step-by-step DNS record creation is covered in How to Add a DKIM Record.
What Is a DKIM Selector (s=) and Why Do Domains Use Multiple Selectors?
A DKIM selector (s=) is a prefix label prepended to ._domainkey.<domain> that allows a single domain to publish multiple independent public keys in DNS simultaneously.
Each email service provider (including Google Workspace, Microsoft 365, SendGrid, Mailchimp, and Resend) generates an independent private key and publishes its public key under a dedicated selector (<selector>._domainkey.example.com), unlike SPF Record where all senders share a single root v=spf1 string. DKIM selector isolation allows administrators to add, rotate, or revoke keys for one provider without disrupting other sending streams because each service signs messages with its own private key.
Because DNS does not permit wildcard enumeration of _domainkey subdomains, verifying a domain's DKIM public key requires querying the exact selector string. The table below lists the default DKIM selector names and DNS record types used by 8 major email providers.
| Email Service Provider (ESP) | Default Selector Name(s) (s=) | DNS Record Type | Full Lookup Hostname Example |
|---|---|---|---|
| Google Workspace | google (or custom prefix) | TXT (2048-bit RSA) | google._domainkey.example.com |
| Microsoft 365 (Exchange Online) | selector1, selector2 | CNAME (rotation pair) | selector1._domainkey.example.com |
| SendGrid (Twilio) | s1, s2 | CNAME (Automated Security) | s1._domainkey.example.com |
| Mailchimp (Intuit) | k2, k3 (legacy: k1) | CNAME | k2._domainkey.example.com |
| Amazon SES | 3 generated 32-character tokens | CNAME (EasyDKIM) | <token>._domainkey.example.com |
| Resend | resend | TXT (RSA public key) | resend._domainkey.example.com |
| Postmark | <YYYYMMDD>pm (date-stamped) | TXT | 20261028pm._domainkey.example.com |
| Klaviyo | kl, kl2 | CNAME | kl._domainkey.example.com |
Identifying an active selector requires inspecting outgoing message headers: administrators send a test message to an external account, open Show Original or View Message Source, and locate the s= tag within the DKIM-Signature header. Additional guidance on selector discovery and multi-vendor management is available in What Is a DKIM Selector and How to Find Yours and Multiple DKIM Selectors.
How Do 1024-Bit RSA, 2048-Bit RSA, and Ed25519 DKIM Key Lengths Compare?
Modern email standards require a minimum DKIM RSA key length of 1024 bits and recommend 2048-bit RSA or Ed25519 keys while permanently revoking 512-bit keys and the legacy SHA-1 hash algorithm (rsa-sha1). The table below compares the 4 DKIM cryptographic key options by bit length, security status, and DNS TXT string behavior.
| Key | Status | Notes |
|---|---|---|
| 512-bit RSA | Insecure | Rejected by major receivers |
| 1024-bit RSA | Legacy minimum | Increasingly weak; migrate |
| 2048-bit RSA | Current standard | May need two TXT strings for the key material |
| Ed25519 (RFC 8463) | Modern alternative | Shorter keys, faster signing; receiver support still maturing |
DNS administrators split a 2048-bit public key into two quoted 255-character segments when publishing the TXT record manually in a zone file. Authoritative DNS providers split the payload into two contiguous quoted strings (for example, "v=DKIM1; k=rsa; p=MIIBIj..." "...DAQAB"), which resolvers concatenate without spaces during signature verification. Key length trade-offs and browser-based key generation are detailed in DKIM Key Length and the DKIM Record Generator.
What Is DKIM Canonicalization (relaxed/relaxed vs simple/simple)?
DKIM canonicalization is the pre-hashing normalization algorithm that determines whether minor whitespace or header formatting changes in transit invalidate a DKIM signature.
Mail Transfer Agents, security appliances, and intermediary relays regularly modify message formatting during delivery by folding long headers, adjusting tab spacing, or appending blank lines. Canonicalization defines how sending MTAs prepare headers and body text before hashing, and how receiving MTAs reconstruct them before cryptographic verification.
The DKIM standard defines 2 canonicalization algorithms configured independently for headers and body content:
- simple Canonicalization (c=simple/simple): Tolerates zero modification to whitespace, line wraps, or empty lines. The recalculated hash fails to match bh= or b= and triggers a dkim=fail result under simple canonicalization if an intermediate mail relay adds a single space or re-wraps a header line.
- relaxed Canonicalization (c=relaxed/relaxed): Converts header field names to lowercase, unfolds line wraps, collapses multiple whitespace characters into a single space, and ignores trailing blank lines in the message body. Relaxed canonicalization functions as the production industry standard because legitimate transport formatting does not break signature integrity.
Standard production deployments configure c=relaxed/relaxed on all outbound mail streams to prevent legitimate formatting changes from triggering verification failures. Deep canonicalization algorithms and troubleshooting steps are detailed in DKIM Canonicalization and DKIM Failing? Diagnosis and Fixes.
Why Does DKIM Survive Email Forwarding (And How Does It Power DMARC Alignment)?
DKIM survives email forwarding because its cryptographic signature (DKIM-Signature) is bound to the message headers and body rather than the connecting server's IP address, allowing DMARC to pass via DKIM alignment (adkim) even when forwarding breaks SPF.
The forwarding server's IP address fails the original sender's SPF check when a recipient auto-forwards an email to another inbox. Because the DKIM-Signature header travels inside the message payload, destination mail servers verify the cryptographic signature using the sender's public key in DNS. The message passes DMARC through DKIM alignment (adkim) if the signing domain in d= matches the domain in the visible From: header, ensuring uninterrupted inbox delivery as explained in SPF vs DKIM and DKIM vs DMARC.
An attacker captures a legitimate email signed by a domain, preserves the intact DKIM-Signature, and retransmits the signed message to unauthorized recipient lists from botnet IP addresses during a DKIM replay attack. Mail systems neutralize replay attacks through 3 operational safeguards:
- Oversigning sensitive headers: Declaring duplicate headers in
h=From:To:Subject:Date:Message-IDprevents attackers from prepending new recipients without breaking the signature hash. - Setting signature expiration timestamps (x=): Declaring an expiration epoch in the signature limits the validity window during which a captured message can be replayed.
- Executing regular key rotation: Rotating cryptographic key pairs every 6 to 12 months across alternating selectors invalidates old captured signatures.
Domain administrators isolate sending services and manage dual-key rotation strategies using the configurations detailed in Multiple DKIM Selectors.
How Do You Set Up and Verify DKIM for Your Domain? (4 Steps)
To deploy and verify DKIM authentication for your domain, complete 4 sequential key generation, DNS publication, signing activation, and verification steps.
Configuring production DKIM follows 4 sequential stages:
- Generate a 2048-bit RSA (or Ed25519) key pair and selector label inside your Email Service Provider's administration portal (or generate custom keys using the DKIM Record Generator for on-premise mail servers).
- Publish the public key as a DNS TXT record (starting with
v=DKIM1; k=rsa; p=...) or configure the provider's delegated CNAME records at<selector>._domainkey.<yourdomain>(ensuring proxy services such as Cloudflare Orange Cloud remain set to DNS Only / Grey Cloud on DKIM CNAME entries). - Enable outbound DKIM signing within your mail provider dashboard once the DNS records propagate globally.
- Verify the published public key, selector configuration, and cryptographic validity using the DKIM Record Checker or by executing terminal queries with
dig +short TXT <selector>._domainkey.example.com, as described in Check SPF, DKIM and DMARC with dig.
Maintaining high email deliverability and protecting domain reputation in modern mail ecosystems relies on DomainKeys Identified Mail (DKIM) signatures, isolated selector namespaces, 2048-bit RSA public keys, and strict DMARC alignment. Domain administrators can verify live public keys, test selector records, and inspect outbound message headers across all sending providers with the DKIM Record Checker.
Frequently asked questions
How many DKIM records can a domain have?+
A domain can publish an unlimited number of DKIM records because each service or key pair lives under its own unique selector subdomain (selector._domainkey.example.com), avoiding any single-record or 10-lookup limit.
How do I find my domain's DKIM selector?+
Send a test email from your mail service, view the raw message source ("Show Original" in Gmail), and locate the s= tag inside the DKIM-Signature header, or paste the headers into the Email Header Analyzer.
Should I use a 1024-bit or 2048-bit DKIM key?+
Use a 2048-bit RSA key (or Ed25519 where supported) for all production domains. Keys shorter than 1024 bits (such as 512-bit) are permanently revoked and rejected by major mailbox providers. In production email deployments, we recommend rotating DKIM key selectors every 6 to 12 months using overlapping dual-selector publishing to maintain continuous signature validation during key updates.
Why does Cloudflare break my DKIM CNAME record if proxied?+
Enabling Cloudflare's HTTP proxy (Orange Cloud) on a _domainkey CNAME record rewrites the CNAME into Cloudflare A and AAAA IP addresses, hiding the target TXT public key. Always set DKIM CNAMEs to DNS Only (Grey Cloud). In practice, this represents one of the most common onboarding errors for organizations adopting third-party transactional email providers behind Cloudflare.
Last verified: 2026-10-31