Home/Guides/Generating DKIM Keys
DKIM Setup

Generating DKIM Keys

Create secure RSA key pairs for DKIM email authentication. Learn proper key sizes, generation methods, and DNS publishing.

7 min read
Technical

What Are DKIM Keys?

DKIM uses public-key cryptography to sign emails. You need two keys:

Private Key

Kept secret on your mail server. Signs outgoing emails.

Stored on mail server
Never shared publicly
Used to create signatures

Public Key

Published in DNS. Receiving servers use it to verify signatures.

Published as DNS TXT record
Publicly accessible
Used to verify signatures

Choosing the Right Key Size

DKIM supports different RSA key sizes. Larger keys are more secure but slower to process.

2048-bit RSA

RECOMMENDED

Industry standard. Excellent security with good performance.

Supported by all major email providers
Secure for 10+ years
Fast signature verification

4096-bit RSA

HIGH SECURITY

Maximum security. Use for highly sensitive environments.

Future-proof security
Slower signature generation
Larger DNS records (may exceed 255 chars)

1024-bit RSA

NOT RECOMMENDED

Weak security. Being deprecated by major providers.

Vulnerable to modern attacks
Google/Microsoft rejecting 1024-bit keys
Best Practice

Use 2048-bit RSA keys for the best balance of security and performance. Only use 4096-bit if you have specific compliance requirements.

How to Generate DKIM Keys

There are three main ways to generate DKIM keys:

1

Using OpenSSL (Command Line)

Best for Linux/Mac servers. Gives you complete control.

Step 1: Generate Private Key
openssl genrsa -out dkim_private.pem 2048

Creates a 2048-bit RSA private key

Step 2: Extract Public Key
openssl rsa -in dkim_private.pem -pubout -outform der 2>/dev/null | openssl base64 -A

Outputs base64-encoded public key for DNS

Secure Your Private Key!

Set strict permissions: chmod 600 dkim_private.pem. Never share this file.

2

Using Your ESP Dashboard

Easiest method. Most email providers generate DKIM keys automatically.

Google Workspace

Admin Console → Apps → Google Workspace → Gmail → Authenticate Email → Generate New Record

Microsoft 365

Exchange Admin Center → Mail Flow → DKIM → Enable for your domain

SendGrid/Mailchimp/Postmark

Domain Authentication settings → Generate DKIM keys automatically

Benefit: ESP manages key rotation and storage automatically.

3

Using Online DKIM Generators

Quick option for testing. Use with caution for production.

Security Warning

Online tools see your private key during generation. Only use reputable sources or generate keys locally for production systems.

Publishing DKIM Keys to DNS

After generating keys, publish the public key as a DNS TXT record.

DNS Record Format:

Record Name (Hostname):
[selector]._domainkey.yourdomain.com

Example: default._domainkey.example.com

Record Type:
TXT
Record Value:
v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC...

• v=DKIM1 (version)
• k=rsa (key type)
• p=... (public key in base64)

Verify DNS Propagation

Check your DKIM record is published correctly:

nslookup -type=txt default._domainkey.yourdomain.com

Testing Your DKIM Keys

After publishing, verify DKIM is working correctly.

Verification Checklist:

Check DNS record

Use DKIM checker tool or command line to verify public key is published

Send test email

Send to Gmail, check email headers for DKIM=pass

Review DMARC reports

Monitor DKIM alignment in aggregate reports

DKIM Key Rotation Best Practices

Rotate DKIM keys periodically to maintain security.

Recommended Schedule:

Every 6-12 monthsStandard

Regular rotation for good security hygiene

ImmediatelyIf Compromised

Rotate if private key is exposed or server is breached

Related Guides

Verify Your DKIM Setup

Use our free DKIM checker to verify your keys are published correctly, or let our platform manage DKIM across all your domains.

Free DKIM Tools