Skip to content

DKIM explained: how email signing works

Section 1 of 11
Size 3 of 5

Professional email05/08Part of the “Professional email for your company” track · Article 6 of 13

DKIM explained: how email signing works

How DKIM signs your mail and how receivers verify it: the key in DNS, selectors for several senders, key size and rotation, and what breaks a signature.

Abdulwahed MohammadContent writer at tech+15 min read

A patient at a clinic in Manama receives an email with her test results and a link to the clinic’s portal. How does her mail server know that this message really left the clinic’s systems, and that nobody changed the link on the way? That is the question DKIM answers. , short for DomainKeys Identified Mail and defined in RFC 6376, lets the sending server sign each message with a private key, and lets any receiving server check that signature with a public key the domain owner publishes in DNS. In the previous article on SPF we saw how a domain lists the servers allowed to send for it. SPF checks the sending server’s address; DKIM checks the message itself, which is why it survives many cases where SPF fails. This article explains how signing and verification work, what the record in DNS looks like, how selectors let several services sign for one domain, how to read a DKIM-Signature header, which key sizes and algorithms to use, how to rotate keys, and what breaks a signature on the way.

01What DKIM proves, and what it does not

A DKIM signature makes two promises. First, that a holder of the private key for a given domain signed this message. Second, that the parts it signed, the body and a list of chosen headers, have not changed since. If either promise fails, the receiving server records the result as fail, and it never sees the message as signed by that domain.

What DKIM does not promise matters just as much:

  • It does not prove the visible sender: The signing domain sits in the d= tag, and it can be any domain the signer holds a key for. A spammer can sign perfectly valid mail with his own domain while the From line shows yours. Tying the signature to the From line is DMARC’s job, which we cover in the next article.
  • It does not encrypt anything: The message stays readable on the way. Encryption in transit is TLS’s job between servers.
  • It does not say the content is good: A signed message can still be spam. The signature gives the receiver a stable name to attach reputation to: mail signed by a domain that behaves well builds trust over time.
  • It is not a policy: A message without a signature, or with a broken one, is not rejected because of DKIM alone. RFC 6376 says a signature that fails is to be ignored as though it were not there, and the decision is left to the receiver’s other checks and to DMARC.

02How signing and verification work

Signing happens on the last server under your control before the message leaves, such as the hosting server that sends your mail, or the newsletter platform’s servers. Verification happens on the receiving server. In order:

  1. 01Hashing the body: The sending server prepares the body in a standard form, then computes its SHA-256 hash and writes it in the bh= tag. This is the .
  2. 02Choosing the headers: It picks the headers to sign, at least From, and usually Subject, Date, To, Message-ID and others, and lists their names in the h= tag.
  3. 03Signing: It signs those headers together with the DKIM-Signature header itself, which already holds the body hash, using the private key, and writes the result in the b= tag.
  4. 04Fetching the key: The receiving server reads d= and s= from the header and asks DNS for the TXT record at the name s._domainkey.d.
  5. 05Checking the body: It prepares the body it received the same way, computes its hash and compares it with bh=. Any difference means the body changed.
  6. 06Checking the signature: It verifies b= with the public key over the same headers. If both checks pass, the result is pass, written into the Authentication-Results header the server adds.

The private key never leaves the signing server, and the public key is open to everyone in DNS. That separation is the core of the design: anyone can verify, and only you can sign.

03The public key in DNS

The key is published as a TXT record under a name made of three parts: the , then the fixed word _domainkey, then the domain. For a clinic whose domain is ibtisamat-manama.com and whose selector is s2026, the record looks like this:

A DKIM public-key record in DNS
# Names2026._domainkey.ibtisamat-manama.com# Type: TXT. Value (the key is cut short here; yours is one long line)v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx3...IDAQAB
TagMeaningNotes
v=DKIM1The record’s versionOptional, but if present it must come first
k=rsaThe key typersa is the default; ed25519 is the other type in use
p=The public key in Base64Required. An empty p= means the key has been revoked
t=yTest modeThe domain is testing DKIM: receivers treat its mail as if unsigned
t=sStrictThe i= identity must be exactly the d= domain, not a subdomain of it
h=Allowed hash algorithmsRarely needed; sha256 is what you use

A 2048-bit key is about 400 characters long, and a single string inside a TXT record cannot exceed 255 characters. DNS solves this by splitting the value into several quoted strings that the receiver joins together. Good control panels do the split for you; if you add the record by hand and your panel asks for one value, paste it whole and let the panel handle it.

04Selectors: several senders, one domain

The selector is what lets one domain have several keys at once. Each service that sends in your name signs with its own private key, publishes its public key under its own selector, and puts that selector in the s= tag of every message, so the receiver knows which record to fetch. Picture an online shop in Muharraq, dukkan-isatown.com, that sends mail from four places:

SenderSelectorRecord nameRecord type
The staff mailboxes on cPanel hostingdefaultdefault._domainkey.dukkan-isatown.comTXT with the key
The newsletter platforms1 and s2s1._domainkey.dukkan-isatown.comCNAME to the platform
The CRM that sends quotescrm2026crm2026._domainkey.dukkan-isatown.comTXT with the key
The shop’s order notificationsshopshop._domainkey.dukkan-isatown.comTXT with the key

The four records live side by side without conflict, unlike SPF, where a domain may have only one record. That makes DKIM the easier way to authorise a new service: you add its record, and nothing else changes.

Pay attention to the d= domain, though. Many platforms sign by default with their own domain, which gives a valid signature that does nothing for your domain under DMARC. Look in the platform’s settings for “authenticate your domain” or “custom DKIM” so it signs with d=dukkan-isatown.com. Gathering every sender and fixing them one by one is the subject of the rollout plan article.

05Reading a DKIM-Signature header

Open the full headers of a message from your account (in Gmail, “Show original”; in Outlook, “View message source”) and look for the DKIM-Signature header. Here is a signature from a school in Riffa sending a notice to parents:

A DKIM-Signature header, with the signature cut short
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=madrasat-aldana.com; s=s2026; t=1764489600; h=from:to:subject:date:message-id:mime-version:content-type; bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=; b=Kx9T2c...q1Vw==
TagWhat it tells you
v=1The DKIM version; always 1
a=rsa-sha256The signing algorithm: an RSA key with a SHA-256 hash
c=relaxed/relaxedCanonicalization for the headers, then for the body
d=madrasat-aldana.comThe domain that takes responsibility for the message
s=s2026The selector, so the key is at s2026._domainkey.madrasat-aldana.com
t=When it was signed, in seconds since 1970
x=An optional expiry time, after which the signature no longer counts
h=The signed headers, in order
bh=The hash of the body
b=The signature itself
l=An optional length: only this many bytes of the body are signed

Then look for the result the receiving server wrote. In Authentication-Results you will find a line such as dkim=pass header.d=madrasat-aldana.com header.s=s2026. If it says fail, the line often adds a reason such as body hash did not verify, which means the body changed, or no key for signature, which means the record is missing or its name is wrong.

06Canonicalization: simple and relaxed

On its way a message passes through several servers, and some of them change small things that do not affect its meaning: they fold a long header onto two lines, change a header name’s case, or add spaces at the end of a line. Any change of a single byte breaks the hash. That is why DKIM defines : both the signer and the verifier turn the message into a standard form before hashing it. There are two modes, chosen separately for the headers and the body in the c= tag:

ModeHeadersBody
simpleNothing is changed: any folding or case change breaks the signatureOnly empty lines at the end of the body are ignored
relaxedHeader names in lower case, folding undone, runs of spaces made oneSpaces at line ends removed, runs of spaces made one, empty lines at the end ignored

If c= is missing, the default is simple/simple, the most fragile choice. Use relaxed/relaxed, which most modern signers already choose: it survives the small edits servers make, and it still catches any real change to the text or links.

07Key size and algorithms

RFC 8301 updated DKIM’s cryptography in 2018 with clear rules: rsa-sha1 must not be used for signing or verifying, signers must use RSA keys of at least 1024 bits, and they should use at least 2048. Receivers must not accept a signature with an RSA key shorter than 1024 bits.

ChoiceStatusWhen to use it
RSA 1024 bitsThe minimum allowedOnly if your system cannot do more; plan to replace it
RSA 2048 bitsRecommendedThe default for every new key
RSA 4096 bitsAllowedHard to fit in DNS, and adds little over 2048 for this purpose
Ed25519 (RFC 8463)Standard since 2018Only alongside an RSA signature, because not every receiver verifies it
rsa-sha1BannedNever

If you run your own mail server, you generate the key pair yourself. These commands generate a 2048-bit key and print the public part ready for the p= tag:

Generating a 2048-bit DKIM key with openssl
# Generate the private key (keep it on the mail server only)openssl genrsa -out s2026.private 2048# Extract the public key as one line of Base64 for p=openssl rsa -in s2026.private -pubout -outform der 2>/dev/null | openssl base64 -A

Mail software such as Rspamd and OpenDKIM has its own tool that generates the key and prints the whole record, as we showed in the article on running a mail server on a VPS.

08Rotating keys without breaking mail

means moving signing to a new key every so often, so that a private key that has been stolen or cracked without your knowledge stops being useful. M3AAWG, the industry group that brings mailbox providers and senders together, recommends rotating at least every six months. Selectors make rotation smooth, because the new key goes under a new name without touching the old one:

  1. 01Publish the new key: Generate a new pair and publish its public key under a new selector, such as s2026b, while signing stays on the old key.
  2. 02Wait for DNS: Give the new record time to reach resolvers, at least as long as its TTL, and check that it answers.
  3. 03Switch signing: Point your mail server to the new private key and the new selector.
  4. 04Keep the old key a while: Messages signed with the old key may still be in queues or waiting to be retried, and some receivers verify late. Leave the old record published for at least seven days.
  5. 05Revoke the old key: Change the old record to an empty p=, or delete it, and destroy the old private key.

Services that give you a CNAME record rotate their keys on their side with no action from you, which is one of the benefits of the CNAME approach.

09What breaks a signature on the way

A DKIM signature is meant to break when the message changes, and that is its strength. But some legitimate changes break it too:

  • Mailing lists: Many lists add a tag such as [Members] to the subject, or a footer with an unsubscribe link to the body, so both the signature and the body hash fail. That is why ARC exists, which we cover in the article on MTA-STS, BIMI and ARC.
  • Security gateways: Some filters rewrite links for scanning, or add a warning line such as “external sender” to the top of the body.
  • Re-encoding: A server along the way may convert the body from 8bit to quoted-printable, which changes its bytes even if the text looks the same.
  • Signing headers that get changed: If you sign headers that servers usually add to or change, such as Received, the signature breaks at the first hop.
Problemdkim fails with “no key for signature”
FixThe record is missing or its name is wrong. Make sure it is at selector._domainkey.domain, and that your panel did not add the domain twice, as in s2026._domainkey.ibtisamat-manama.com.ibtisamat-manama.com.
Problemdkim=fail or neutral with “body hash did not verify”
FixThe body changed after signing: a footer added by a list or gateway, or re-encoding. Check whether the failure is limited to one path, and use relaxed for the body.
Problemdkim=fail with “signature did not verify”
FixThe published key does not match the private key in use, often after a key was regenerated without updating DNS. Publish the current public key, or point signing back to the matching key.
ProblemThe key record is cut off or rejected by the panel
FixA 2048-bit key exceeds 255 characters. Let the panel split it into strings, and make sure no spaces or line breaks crept into the middle of the key.
ProblemDKIM passes but DMARC fails
FixThe signature is with the platform’s domain, not yours. Turn on custom DKIM in the platform so the d= domain matches the From domain.

10Checking DKIM yourself

The quickest check is a real message: send one from each service to an outside mailbox, open the full headers and read Authentication-Results. To check the record itself in DNS, ask for it by name:

Checking DKIM records with dig
# Read the key record for the s2026 selectordig +short TXT s2026._domainkey.ibtisamat-manama.com# A service that uses CNAME: see where the name pointsdig +short CNAME s1._domainkey.dukkan-isatown.com

Note that nobody can list all of a domain’s selectors from DNS; you have to know each selector’s name. Keep a short table of your selectors: which service owns each one, when its key was created, and when it is due for rotation.

11DKIM with cPanel hosting and DNS Console at Illevante

If your mail is on Illevante’s cPanel hosting, SPF and DKIM are part of the email service in every plan, from cPanel Start at $2 a month to Power at $4 and Infinity at $6. cPanel signs outgoing mail from your mailboxes, usually with the default selector, and its Email Deliverability page shows the state of the DKIM and SPF records for each domain, with a Manage button that shows the suggested record.

  • Your domain’s DNS is with the hosting: cPanel can install the DKIM record itself with one click from the same page.
  • Your domain’s DNS is in DNS Console: Copy the suggested record from cPanel, then add it as a TXT record in DNS Console under the name default._domainkey, and paste the value as cPanel shows it.
  • You send from other services too: Add each one’s DKIM record in DNS Console under its own selector, as a TXT or CNAME as the service asks, without touching the others.

After any change, send a message to an outside mailbox and read dkim=pass in its headers. The DNS check tool checks your domain’s MX, SPF and DMARC and explains how to fix each problem, but it does not check DKIM, because a selector is not something it can guess, so the message headers or dig are your test for DKIM. And if you plan to bring in a mailbox service such as Acrux Mail, which is coming soon, the Acrux Mail article shows the records it will need. Once DKIM is in place for every sender, the next step is to tie it to your visible address with DMARC.

Test your understanding

Three questions, one minute

⁦0 / 3⁩Set 1

  1. 01Where does a receiving server look for the key of a signature with d=ibtisamat-manama.com and s=s2026?

  2. 02A message passes DKIM with d=mailer-platform.com, and its From line shows dukkan-isatown.com. What does that pass prove?

  3. 03Which key size do the current DKIM rules recommend for RSA?

Ready to start? Power your projects today

Choose the hosting, server or domain that suits your business, and our specialist team is available around the clock to make your projects a success.

A .com domain a year
$17
cPanel hosting per month
$2
CoreVPS servers per month
$3.50