What is DKIM?
DKIM (DomainKeys Identified Mail) is an email authentication mechanism defined in RFC 6376. It allows you to cryptographically sign outgoing emails to prove their origin and integrity.
Why configure DKIM:
- Authenticate your emails — Prove that the email actually comes from your domain
- Protect against tampering — The signature detects any modification to the content
- Improve deliverability — DKIM-signed emails are better accepted by Gmail, Outlook, Yahoo
- Prerequisite for DMARC — DKIM is one of the two pillars of DMARC authentication (along with SPF)
How does DKIM work?
DKIM uses asymmetric cryptography (public/private key):
- Signing on send: Your mail server calculates a hash of the message and signs it with the private key
- DNS publication: The public key is published in a TXT record at
selector._domainkey.domain.com - Verification on receive: The receiving server retrieves the public key via DNS and verifies the signature
Send: Message → Hash → Signature (private key) → DKIM-Signature Header
Receive: Header → Public key (DNS) → Signature verification → Pass/Fail
DKIM record syntax
A DKIM record is a DNS TXT record published at <selector>._domainkey.<domain>:
v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
DKIM tags
| Tag | Description | Required | Values |
|---|---|---|---|
v | Version | Recommended | DKIM1 |
k | Key type | No (default: rsa) | rsa, ed25519 |
p | Public key | Yes | Base64 DER |
h | Hash algorithms | No | sha256, sha1 |
t | Flags | No | y (test), s (strict) |
s | Service types | No | email, * |
n | Notes | No | Free text |
Record examples
RSA 2048 bits (recommended):
default._domainkey.captaindns.com TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkq..."
Ed25519:
default._domainkey.captaindns.com TXT "v=DKIM1; k=ed25519; p=MCowBQYDK2Vw..."
RSA vs Ed25519: which algorithm to choose?
| Criteria | RSA 2048 | RSA 4096 | Ed25519 |
|---|---|---|---|
| Security | Good | Excellent | Excellent |
| Support | Universal | Universal | Partial (~80%) |
| Record length | ~400 chars | ~800 chars | ~90 chars |
| Performance | Good | Slow | Very fast |
| Recommendation | Production | Sensitive | Advanced |
Recommendations
- RSA 2048 bits: Current standard, maximum compatibility. Choose this option by default.
- RSA 4096 bits: For highly sensitive environments. Be aware of DNS limitations.
- Ed25519: For advanced configurations. Consider a dual selector (RSA + Ed25519).
- RSA 1024 bits: Deprecated since 2020. Avoid.
Key lengths and DNS limits
The 255-character limit
DNS TXT records are limited to 255 characters per string. Here's the impact by algorithm:
| Algorithm | Record length | DNS compatible |
|---|---|---|
| Ed25519 | ~90 chars | ✅ Always |
| RSA 1024 | ~230 chars | ✅ Always |
| RSA 2048 | ~400 chars | ⚠️ Auto-split |
| RSA 4096 | ~800 chars | ⚠️ Check provider |
How providers handle long records
Most DNS providers (Cloudflare, AWS Route 53, Google Cloud DNS) automatically split long records into multiple strings. The DNS protocol concatenates them when reading.
If your provider doesn't support long records, prefer RSA 2048 bits or Ed25519.
Practical use cases
New domain: first DKIM configuration
Context: You're setting up a new mail server (Postfix, etc.)
Solution:
- Generate an RSA 2048-bit key with the
defaultselector - Download the private key and configure OpenDKIM
- Publish the TXT record in your DNS zone
- Verify with the DKIM Checker
DKIM key rotation
Context: Your DKIM key is over 12 months old or has been compromised
Solution:
- Generate a new key with a new selector (e.g., s2, 202602)
- Configure the new key in your mail server
- Publish the new DNS record
- Wait 24-48 hours for DNS propagation
- Remove the old record
Dual selector: RSA + Ed25519
Context: You want to benefit from Ed25519 while maintaining RSA compatibility
Solution:
- Generate an RSA 2048 key with the
rsaselector - Generate an Ed25519 key with the
edselector - Configure your server to sign with both keys
- Modern servers will verify Ed25519, older ones will use RSA
DKIM flags: test and strict modes
Flag t=y (test mode)
Activates DKIM test mode. Verification failures are treated as neutral (neither pass nor fail).
Usage: Test your configuration without risking rejections. Remove the flag once validated.
Flag t=s (strict mode)
Requires strict alignment between the DKIM signing domain and the From domain. By default, relaxed alignment allows subdomains.
Usage: Strengthen security in production. Ensure all your emails are signed from the exact domain.
❓ FAQ - Frequently asked questions
Q: How do I generate a DKIM key for my domain?
A: Use our generator: enter your domain and a selector, choose RSA 2048 bits, click Generate. Download the private key and publish the TXT record in your DNS.
Q: What's the difference between RSA and Ed25519?
A: RSA is supported by all servers. Ed25519 is more modern with shorter keys, but support isn't universal (~80%). Recommendation: RSA 2048 bits for production.
Q: What RSA key length should I choose?
A: RSA 2048 bits is the standard. RSA 1024 is deprecated. RSA 4096 offers more security but generates very long records.
Q: What is a DKIM selector?
A: An identifier allowing multiple DKIM keys. Examples: default, google, s1. The record is published at selector._domainkey.domain.com.
Q: Is the private key stored?
A: No. Generated once, transmitted, then deleted. Download it immediately.
Q: Why does my record exceed 255 characters?
A: RSA 4096 generates 800+ character records. Most providers split automatically. Otherwise, prefer RSA 2048 or Ed25519.
Q: How do I configure DKIM with Google Workspace?
A: Google generates its own keys. Admin Console > Gmail > Authenticate email > Generate new record. Our tool is for custom servers.
Complementary tools
| Tool | Purpose |
|---|---|
| DKIM Record Check | Verify your DKIM is published and valid |
| DKIM Syntax Check | Validate DKIM record syntax |
| SPF Generator | Create your SPF record |
| DMARC Generator | Configure DMARC to complete authentication |
| Mail Tester | Test your email deliverability |
Useful resources
- RFC 6376 - DomainKeys Identified Mail (DKIM) Signatures — Official DKIM specification
- RFC 8463 - A New Cryptographic Signature Method for DKIM (Ed25519) — Ed25519 support for DKIM
- RFC 8301 - Cryptographic Algorithm and Key Usage Update to DKIM — Current security recommendations
- OpenDKIM - Configuration Guide — Documentation for Postfix/OpenDKIM
- Google Workspace - Set up DKIM — Official Google guide
- Microsoft 365 - Use DKIM — Official Microsoft guide