Email security

What Is a DKIM Key? How the Key Pair Signs and Verifies Email

A DKIM key is a cryptographic key pair: the private key signs every message you send, and the public key in DNS lets receivers verify the signature. Here is how it works and how to set it up.

Cysoro Security TeamPublished · 9 min read
EMAIL SECURITY DKIM Key The key pair that signs your email. ✉ Outgoing mail DKIM-Signature: v=1; a=rsa-sha256; d= example.com; s=google ✓ dkim=pass private key signs 2048-bit
Quick answer

A DKIM key is a public and private key pair used by DomainKeys Identified Mail. The private key stays secret on the sending mail server and signs selected headers and the body of each outgoing message. The matching public key is published as a TXT record in DNS, so any receiving server can fetch it and verify the signature, proving the message came from your domain and was not altered in transit.

Key takeaways

  • A DKIM key is a key pair: the private key signs outgoing mail, the public key in DNS lets receivers verify the signature.
  • Use a 2048-bit RSA key and a separate selector for each sending service, so one key never has to be shared.
  • DKIM proves a message was not altered, but it does not stop look-alike domains — pair it with SPF and DMARC at p=reject.

Every email your domain sends carries a claim: "this really came from us, and nobody changed it on the way." A DKIM key is what makes that claim checkable. Without one, any receiving server has to take your word for it — and spam filters do not take anyone's word.

What is a DKIM key?

A DKIM key is a public and private key pair used by DomainKeys Identified Mail (DKIM), the email authentication standard defined in RFC 6376. The private key signs your outgoing mail, and the public key, published in DNS, lets any receiving server verify that signature.

The two keys are mathematically linked, but only one is secret. The private key never leaves your mail server or email service. The public key is meant to be read by everyone: it sits in a DNS TXT record that any server on the internet can look up.

Think of it like a wax seal on a letter. The private key is the signet ring that makes the seal, and the public key is the published image of the seal that anyone can compare against.

A matching seal proves the letter came from the ring's owner and was not opened and resealed on the way. If you want the wider picture, our guide to what DKIM is explains where keys fit into email authentication as a whole.

How does a DKIM key work?

When your mail server sends a message, it hashes selected headers and the body, signs that hash with the private key, and adds the result as a DKIM-Signature header. The receiving server reads the signature, fetches the public key from DNS, and checks whether the two match.

Microsoft Learn describes the flow in four steps: private keys are generated for a domain and used to sign important parts of outbound messages; the signature is stored in the DKIM-Signature header; the matching public keys are stored in DNS records; and destination servers use the public key to verify the signature.

If the hashes match, DKIM passes. That proves two things: the message was signed by someone holding your domain's private key, and the signed parts were not changed after signing. If anything in the signed headers or body changed in transit, the check fails.

How a DKIM key signs and verifies mail1. Sending serverhashes headers + body,signs with thePRIVATE keyadds DKIM-Signature2. DNSholds the PUBLIC keyas a TXT record atselector._domainkey.yourdomain.com3. Receiving serverfetches the public key,recomputes the hash,checks the signaturedkim=pass or failThe private key never leaves the sender. The public key is visible to everyone.A pass proves the message was not altered after signing.
DKIM signing and verification in three steps, as defined in RFC 6376. Illustration by Cysoro.

DKIM has one property that makes it the most important of the three email authentication standards: it survives forwarding. SPF breaks when a message is forwarded, because the forwarding server is not in your SPF record. DKIM travels with the message, so a forwarded email can still pass — which is why DMARC depends on DKIM more than on SPF.

What does a DKIM record look like?

The public key lives in a DNS TXT record at an address built from three parts: the selector, the label _domainkey, and your domain. RFC 6376 uses the example brisbane._domainkey.example.com, where brisbane is the selector.

A typical record value looks like this, with the key shortened: v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA.... The p= value is the long base64-encoded public key, often several hundred characters.

TagMeaningExample
v=Version. Must be DKIM1 and appear first.v=DKIM1
k=Key type. Default is rsa; Ed25519 was added by RFC 8463.k=rsa
p=Public key data, base64 encoded. Required. Empty means the key is revoked.p=MIIBIjANBgkq...
t=Flags, rarely used by small senders.t=s
n=Human-readable notes about the key.n=Google Workspace key

The signature header on each message carries its own tags: v= for the version, a= for the algorithm (usually rsa-sha256), c= for canonicalization, d= for the signing domain, s= for the selector, h= for the signed headers, bh= for the body hash and b= for the signature itself. A receiver needs the d= and s= values to know where to look up your public key.

What is a DKIM selector?

A selector is a short name that tells receivers which public key to fetch for a given message. It is part of the DNS address: selector._domainkey.yourdomain.com. One domain can have many selectors, one per sending service, and each service holds its own private key.

That separation is the point. Google Workspace uses google by default, so a Workspace domain publishes its key at google._domainkey.yourdomain.com. Microsoft 365 uses selector1 and selector2. A newsletter tool might use s1 and a transactional mail service something else entirely.

You cannot list a domain's selectors from DNS, because DNS has no way to enumerate them. You find them in the s= tag of real messages, or in each vendor's setup page. That is also why a key leak is contained: revoking one selector's key does not affect the others.

How do you generate a DKIM key?

In practice you almost never generate a key by hand. Your email service creates the key pair for you, and you publish the public half. The steps differ by provider, but the shape is the same everywhere: generate, publish, then switch signing on.

Google Workspace

Google holds the private key, so you only publish what it gives you. In the Admin console, go to Apps, then Google Workspace, then Gmail, then Authenticate email. Select the domain and click Generate new record.

Keep the 2048-bit key length and the default google selector unless you need another prefix. Copy the TXT record name and value into your DNS host, wait for DNS to update, then return and click Start authentication.

Google says it can take up to 48 hours for DKIM to start working after you add the record, and on a brand-new Workspace account the key may only be available 24 to 72 hours after Gmail is turned on.

Microsoft 365

Microsoft 365 works differently: you do not paste a key at all. You add two CNAME records that point into Microsoft's DNS, where Microsoft holds and rotates the keys for you. The records use the hosts selector1._domainkey and selector2._domainkey. Microsoft Learn's DKIM guide walks through the full setup.

In the Microsoft Defender portal, go to Email and collaboration, then Policies and rules, then Threat policies, then Email authentication settings, and open the DKIM tab. Copy the two CNAME values it shows for your domain — do not build them by hand, because the target format changed for custom domains added from May 2025. Publish both records, then switch on signing for the domain.

Generating a key yourself

If you run your own mail server, you can generate a pair with OpenSSL and publish the public half as a TXT record. Use 2048 bits, keep the private key readable only by the mail server process, and never paste the private key into a ticket, a chat message or a DNS record. The public half is the only part that belongs in DNS.

How long should a DKIM key be?

Use 2048 bits. Google's sender guidelines state that sending to personal Gmail accounts requires a DKIM key of 1024 bits or longer, and recommend 2048 bits if your domain provider supports it.

RFC 8301, which updated DKIM's cryptographic rules, says signers must use RSA keys of at least 1024 bits and should use at least 2048 bits. It also retired the old rsa-sha1 algorithm.

A 1024-bit key is the floor, not the target. The longer key costs nothing extra in practice — the record is longer, and a few DNS hosts with short TXT limits may struggle, which is the only real reason to fall back to 1024 bits.

Ed25519 is the newer alternative, added by RFC 8463 in 2018. Its keys are far shorter than RSA keys of equivalent strength, which makes DNS records easier to manage. Support is growing but not universal, so most domains still sign with RSA-SHA256 and will for some time.

Canonicalization matters too. Use c=relaxed/relaxed unless you have a reason not to. The simple mode breaks on small whitespace changes that many mail relays make, which turns legitimate mail into DKIM failures.

How do you rotate a DKIM key?

Keys should be rotated regularly — at least once a year, and immediately if you suspect a private key leaked. Rotation is safe if you do it in the right order, because selectors let the old and new keys exist side by side.

Rotating a DKIM key without breaking mail1New key, new selectorgenerate the pair,name it selector2or a dated name2Publish firstadd the TXT record,wait for DNS tospread (up to 48h)3Switch signingpoint the sender atthe new selectorand confirm passes4Remove the old keyonly after a week ofclean passes onthe new oneNever delete the old key before the new one is signing. Mail in flight still needs it.
Safe DKIM key rotation in four steps. Illustration by Cysoro.
  1. Generate a new key pair with a new selector. Use a different selector name, such as a dated one, so the two keys never collide.
  2. Publish the new public key first. Add the TXT record and wait for DNS to propagate — up to 48 hours.
  3. Switch signing to the new selector in your mail service, then send test messages and confirm dkim=pass.
  4. Remove the old key only after a week of clean passes. Mail already in flight may still need it.

Microsoft 365 rotates between selector1 and selector2 for you, and its documentation says a rotated key takes four days (96 hours) before it starts signing. If you manage keys yourself, set a calendar reminder so rotation actually happens.

What a DKIM key does not do

DKIM proves a message was signed by your domain and not altered afterward. It does not prove the sender is who they claim to be in any broader sense, and it does not protect you on its own.

CheckWhat it provesWhat it does not prove
DKIMThe message was signed by the domain and not altered in transitThat the sender is trustworthy, or that the domain is not a look-alike
SPFThe sending server is authorized for the domainThat the message content was not altered
DMARCThe From domain aligns with SPF or DKIM, and what to do on failureAnything on its own — it needs SPF or DKIM underneath

DKIM does not encrypt anything: anyone who can read the message can still read it. It does not stop an attacker from registering a look-alike domain and signing mail from it with a perfectly valid DKIM key of their own. And it does not validate who sent the email from a network perspective — that is SPF's job.

That is why the three standards work as a set. DKIM signs, SPF authorizes the sender, and DMARC ties the From domain to one of them and tells receivers what to do when the checks fail. Our guide to what DMARC is explains how to move a domain from monitoring to enforcement.

How do you check that your DKIM key works?

Check the record, then check a real message. Both take a minute, and both catch different mistakes.

First, query the public key directly: dig +short TXT google._domainkey.yourdomain.com should return a record starting with v=DKIM1. If it returns nothing, the record is missing or has not propagated yet. You can also run your domain through our free DKIM checker, which shows the record and its key length.

Second, send a test message to an address you control and read the Authentication-Results header. Look for dkim=pass with your domain in the d= value. If it says fail, the usual causes are a copied key with a missing character, the wrong selector, or a signature that covers headers your mail service changes after signing.

Common mistakes to check in order: the TXT record value was split across lines by the DNS editor; the record was added to the wrong zone; or signing was never switched on after publishing the key.

Another frequent cause is a mismatch: the selector in the record does not match the selector the service signs with. In Google Workspace, remember that publishing the record alone does not turn on signing — you must return to the Admin console and click Start authentication.

The bottom line

A DKIM key is a simple idea with an outsized effect: one private key signs your mail, one public key in DNS lets the world verify it. Generate a 2048-bit key, give each sending service its own selector, publish the public half, switch signing on, and rotate the key at least once a year.

Then do not stop there. DKIM on its own will not stop spoofing of look-alike domains or enforce anything when a check fails — that needs SPF alongside it and a DMARC policy that moves to p=reject.

Check your domain now with the free DKIM checker.

Then run the DMARC checker to see whether your policy actually enforces the result.

Frequently asked questions

What is a DKIM key in simple terms?

It is a pair of cryptographic keys for your email. The private key signs every message you send, and the public key sits in your DNS records so receiving servers can check the signature and confirm the message is genuine and unchanged.

Where is a DKIM key stored?

The private key stays secret on your mail server or email service, such as Google Workspace or Microsoft 365. The public key is published in DNS as a TXT record at an address made from a selector, like google._domainkey.yourdomain.com.

What is a DKIM selector?

A selector is a short name that tells receivers which public key to fetch. It is part of the DNS address, as in selector._domainkey.yourdomain.com. Each sending service gets its own selector, so Google Workspace, Microsoft 365 and a newsletter tool can all sign for the same domain.

How long should a DKIM key be?

Use 2048 bits. Google requires a DKIM key of at least 1024 bits for mail sent to personal Gmail accounts and recommends 2048 bits. The DKIM standard, updated by RFC 8301, says signers must use at least 1024 bits and should use at least 2048.

Does DKIM encrypt my email?

No. DKIM signs email, it does not encrypt it. Anyone who can read the message can still read it. The signature only proves the message came from your domain and was not altered after signing.

How do I check if my DKIM key is working?

Send a test message to an address you control, then look at the Authentication-Results header for dkim=pass. You can also query the public key directly with dig, or run your domain through our free DKIM checker to see the record and its key length.

What happens if my DKIM key is wrong or missing?

Receiving servers cannot verify your mail, so messages are more likely to be marked as spam or rejected. Since February 2024, bulk senders to Gmail and Yahoo must have DKIM in place, so a missing key can stop delivery entirely for high-volume senders.

Sources

  1. IETF — RFC 6376: DomainKeys Identified Mail (DKIM) Signatures
  2. Microsoft Learn — How to use DKIM for email in your custom domain
  3. Google — Email sender guidelines
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against RFC 6376, Microsoft Learn's DKIM documentation and Google's email sender guidelines.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free