Why You Must Rotate Cryptographic Keys: Beyond Set-and-Forget
Many administrators treat DKIM as a one-time setup task—generate keys, publish DNS records, configure your mail server, and forget about it for years. This approach creates significant security risks. Cryptographic key rotation (regularly replacing your key pairs) is essential for several reasons:
- Compliance requirements: Security frameworks like PCI-DSS (for organizations handling credit card data), HIPAA (healthcare), and SOC 2 require periodic cryptographic key rotation, typically every 6-12 months.
- Undetected compromise: If an attacker steals your private key without your knowledge (through a server breach, insider threat, or leaked backup), they can send authenticated emails as your domain indefinitely. Regular rotation limits the window of exposure.
- Staff turnover: Employees or contractors who had access to your DKIM private keys may retain that access after leaving. Rotation ensures former team members cannot abuse old keys.
- Cryptographic lifespan: Even without a known breach, cryptographic keys weaken over time as computing power increases and new attack methods emerge. What's secure today may be vulnerable in 18 months.
Industry best practices recommend rotating DKIM keys every 6 to 12 months. Some high-security organizations rotate quarterly. However, naive rotation—simply replacing the old DNS record with a new one—causes catastrophic email delivery failures. This guide walks you through zero-downtime rotation.
The Dangers of Instant Key Replacement: Why Timing Matters
If you directly overwrite your DKIM DNS record or delete the old key before the new one is active, here's what happens:
- DNS propagation delay: When you change a DNS record, the update doesn't reach all DNS resolvers instantly. DNS records have a Time-To-Live (TTL) value, typically 300-3600 seconds (5-60 minutes), during which resolvers cache the old record. In practice, due to intermediate DNS caches, some resolvers may retain the old record for 24-48 hours.
- Verification failures: During this propagation window, receiving servers will fetch either the old (soon-to-be-deleted) key or the new key depending on which DNS resolver they use. If your mail server switches to signing with the new private key immediately, some receivers will try to verify using the old public key and fail. If you keep signing with the old key, emails sent after the old DNS record is deleted will also fail.
- In-flight emails: Email isn't instantaneous. When you send a message, it may queue at intermediate mail transfer agents (MTAs) for minutes or hours due to greylisting, throttling, or temporary delivery failures. If the receiving server verifies the signature after your key rotation, it might fetch a DNS record that no longer contains the correct public key.
- DMARC enforcement impact: DKIM failures trigger DMARC policies. If you have a strict DMARC policy (p=reject), a sudden spike in DKIM failures will cause legitimate emails to be rejected or sent to spam, potentially damaging your sender reputation and business operations.
The solution is a phased, dual-key rotation that maintains at least one valid key at all times, with an overlap period that accounts for DNS propagation, email queuing, and verification delays.
Step 1: Generating the New Selector & Key Pair
The first step happens entirely on your mail server or email service provider dashboard. Do not touch DNS yet.
Using OpenSSL (for self-managed mail servers)
# Generate a 2048-bit RSA private key
openssl genrsa -out dkim_private_2026.pem 2048
# Extract the public key
openssl rsa -in dkim_private_2026.pem -pubout -out dkim_public_2026.pem
# Convert public key to DKIM DNS TXT format (base64)
openssl rsa -in dkim_private_2026.pem -pubout -outform DER | openssl base64 -A
Choosing the New Selector Name
Pick a selector name that indicates its purpose and creation date. For example:
2026-06(clear date-based rotation)v2-rotated(version tracking)s2-prod-2026(purpose + date)
Important: Do not reuse your old selector name. Using a new selector is what enables dual-key operation. If you reuse the same selector name, you force an instant, dangerous swap because DNS can only hold one record per selector.
At this stage, your mail server now has two private keys: the old key (still active) and the new key (not yet used). Both are safe on your server. Do not start signing with the new key yet.
Step 2: Staging the Public Key in DNS Records
Now you'll publish the new public key in DNS, without removing the old record. Both selectors will coexist in your DNS zone.
Create a new TXT record at: [new-selector]._domainkey.yourdomain.com
The record value follows the standard DKIM format:
v=DKIM1; k=rsa; p=YOUR_BASE64_PUBLIC_KEY
If your DNS provider has a 255-character per-string limit, split the base64 key into quoted chunks:
"v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC..." "...remaining..." "...final chunk"
Set the TTL (Time-To-Live) for this new record to 300 seconds (5 minutes) or lower. A short TTL allows faster changes if you need to correct errors. Your old record should ideally also have a short TTL; if it currently has a long TTL (e.g., 86400 seconds / 24 hours), consider reducing it a few days before rotation.
Verification: Use our DKIM Checker or command-line tools to confirm the new record resolves correctly:
dig TXT [new-selector]._domainkey.yourdomain.com
At this point, both your old and new public keys are live in DNS. Your mail server is still signing exclusively with the old private key. Receiving servers can still verify old signatures, and the new key is available but unused.
Step 3: Transitioning Mail Server Signing
After confirming the new DNS record is active and resolving (wait at least the old record's TTL, typically 5-60 minutes), configure your mail server to begin signing outgoing emails with the new private key.
The specific steps depend on your MTA or ESP:
Postfix with OpenDKIM
Edit /etc/opendkim.conf or /etc/opendkim/KeyTable to add the new selector and key file, then restart OpenDKIM.
Microsoft Exchange Online
In the Exchange Admin Center, navigate to Mail flow → DKIM, select your domain, and click "Rotate DKIM key." Exchange handles selector management automatically.
Google Workspace
In the Google Admin console, go to Apps → Gmail → Authenticate email. Generate a new DKIM key, which automatically creates a new selector. Copy the new DNS record, publish it (without removing the old), then click "Start signing" for the new key. Google will dual-sign for a transition period.
Third-party ESPs (Mailchimp, SendGrid, etc.)
Most ESPs provide a "Rotate key" or "Add new selector" option in their domain authentication settings. Follow their documentation for adding a secondary DKIM configuration.
Dual-signing period: Ideally, configure your server to sign with both the old and new keys simultaneously for a period. This ensures emails are verifiable regardless of which DNS record a receiving server has cached. Not all MTAs support dual-signing; check your documentation.
Step 4: Maintaining Dual-Key Verification Overlap
After your mail server starts signing with the new key, you must maintain both DNS records (old and new) for an overlap period. This is the most critical—and most frequently skipped—step in zero-downtime rotation.
Why Overlap Is Necessary
- DNS cache persistence: Some DNS resolvers may have cached your old DNS record for up to the TTL value (potentially 24-48 hours if you had a long TTL). Emails verified by those resolvers will look up the old selector and fail if the record is gone.
- Email queue delays: Emails sent just before you switched signing may still be in transit. When they finally reach the receiving server, it will expect to verify using the old key. If the old DNS record is deleted, these delayed emails fail authentication.
- Forwarding and archiving systems: Email forwarding services, archiving solutions, and security gateways may re-verify DKIM signatures hours or days after original receipt. They need access to the original public key.
Recommended Overlap Duration
Minimum: 7 days
Standard: 10-14 days
Conservative: 30 days
During this overlap period, your DNS zone contains both the old and new DKIM records. Your mail server signs with the new key (and optionally also the old key). Receiving servers can verify using either key successfully.
Monitor your DKIM authentication rates during the overlap using DMARC aggregate reports or our DKIM Checker's monitoring features. You should see no increase in DKIM failures. If failures spike, extend the overlap period.
Step 5: Safely Revoking the Old Key
After the overlap period (minimum 7 days, ideally 14 days), you can safely remove the old DKIM DNS record. However, consider a phased revocation approach:
Option A: Direct Deletion (Safe after Overlap)
Simply delete the old selector's TXT record from your DNS zone. Verify with DNS lookup tools that the record no longer resolves. After DNS propagation (which can take up to the old record's TTL), the old key is fully revoked.
Option B: Explicit Revocation (More Secure)
Instead of deleting the record immediately, replace the public key value with an empty value:
v=DKIM1; k=rsa; p=
This explicitly tells receiving servers that this selector is revoked and has no valid public key. Explicit revocation prevents any possible future use of the old key, even if the record remains in DNS caches. After 48 hours of explicit revocation, delete the record entirely.
Important: Ensure your mail server no longer attempts to sign with the old private key before or during revocation. If it does, emails will fail verification.
After revocation, monitor your authentication reports for any unexpected failures. A small number of failures is normal in the first 24 hours as caches expire, but sustained failures indicate a problem.
Establishing an Automated Rotation Schedule
Manual key rotation is error-prone and easy to postpone or forget. Modern email infrastructure supports automated DKIM rotation with zero human intervention:
CNAME Delegation (Best Practice)
Instead of publishing your DKIM public keys directly as TXT records, publish CNAME records that point to your email provider's DNS zone:
[selector]._domainkey.yourdomain.com CNAME [selector]._domainkey.provider.com
When the provider rotates keys, they update their DNS zone, and your domain automatically inherits the change. No DNS changes required on your side. This is how Google Workspace, Microsoft 365, and most major ESPs handle DKIM rotation.
Scripted Rotation with DNS APIs
If you self-host your mail server and DNS (e.g., using Cloudflare, Route53, or another provider with an API), write scripts that:
- Generate new key pairs monthly or quarterly
- Publish the new selector's TXT record via API
- Wait for DNS propagation (check via API)
- Update your MTA configuration to add the new selector (reload config)
- Wait the overlap period (configurable)
- Delete or revoke the old selector via API
- Remove the old private key from your MTA
Calendar Reminders for Manual Rotation
If automation isn't possible, set calendar reminders every 6 months with a checklist:
- 2 weeks before: Reduce TTL on existing DNS records to 300 seconds
- 1 week before: Generate new keys and selector
- Day 0: Publish new DNS record
- Day 1: Configure mail server to sign with new key (dual-sign if possible)
- Day 8-14: Revoke old key
- Day 30: Remove old private key from server
Final Recommendation: Use our DKIM Checker to verify configuration integrity at every stage of rotation. Run checks before starting (baseline), after publishing the new record, after switching signing, and after revocation. The tool's historical monitoring helps identify when old keys are no longer being used.
