By Ahmet Karaca · Updated · Checked against RFC 6376 (DKIM), RFC 8301 (DKIM key sizes), RFC 8463 (Ed25519 for DKIM), RFC 1035 (DNS) and Amazon SES: bring your own DKIM key on
Who needs to generate a DKIM key
This tool is for mail you sign yourself: a Postfix server with OpenDKIM, a Mailcow or similar mail server suite, or any other setup where your own machine adds the DKIM-Signature header. You create the key pair, publish the public half in DNS and install the private half on the server that signs.
Hosted providers usually work the other way round. Google Workspace and Microsoft 365 generate the key themselves, keep the private half on their servers and show you the DNS records to publish, so there is nothing to generate here for them; follow their own steps instead, for example in the Google Workspace setup guide or the Microsoft 365 setup guide. Amazon SES does it by default too, but also lets you bring your own RSA key of up to 2048 bits; the Amazon SES setup guide covers its default setup. The setup guides cover the other providers.
What the generator produces
Two halves of one key. The public key goes into a TXT record at selector._domainkey.yourdomain.com, in the form v=DKIM1; k=rsa; p=…, where p= holds the key in base64. Receivers fetch that record and check each signature against it. For RSA, p= holds the key in the SubjectPublicKeyInfo form, the same form RFC 6376's own example in Appendix C produces. For Ed25519, RFC 8463 defines p= as the raw 32-byte public key, which is only 44 characters in base64, and the record says k=ed25519.
The private key comes as a PEM file in the PKCS#8 format, beginning with -----BEGIN PRIVATE KEY-----. Signing software differs in which key formats it accepts, so check your signer's documentation and convert the file if it asks for another format. Whoever has this file can sign mail as your domain: keep it on the signing server only, readable by the signing software, and never paste it into email, chat or a ticket.
If you aren't sure what a selector is or why the key lives in DNS, read what DKIM is and how it works first.
Publishing the record
- Create a TXT record. Its name is the selector followed by
._domainkey; if your DNS panel adds the domain automatically, the host field takes onlyselector._domainkey. - Paste the one-line value. If the panel rejects it as too long, paste the split form with its quoted strings instead.
- Install the private key on your server and configure the signer with the same domain and selector.
- Wait for the record to appear, then run the DKIM checker with your selector to confirm receivers can read the key.
- Send yourself a message and look for
dkim=passin its headers. How to find your DKIM selector shows where the signature sits.
Rotating keys
Selectors exist so a domain can change keys without a gap. RFC 6376 describes the routine: publish the new key under a new selector while the old one is still in DNS, switch the signing server to the new private key, and remove the old record once mail signed with it is no longer in transit. That is why the suggested selector carries the year and month: the next key gets the next date, and the record names show which key is newer.
To revoke a key on purpose, for example after a server was compromised, you can publish its record with an empty p=. Receivers must then treat signatures made with that key as failed (RFC 6376). Deleting the record makes those signatures fail too, and RFC 6376 gives the two no different meaning; an empty p= just says openly that the selector is known and retired.