Suped

What causes invalid RSA public key errors in DKIM records and how can I fix it?

Michael Ko profile picture
Michael Ko
Co-founder & CEO, Suped
Published 20 May 2025
Updated 25 May 2026
10 min read
Summarize with
A broken DKIM public key being repaired inside a DNS record.
An invalid RSA public key error in a DKIM record means the public key inside the p= tag is not a valid base64-encoded RSA public key. The common cause is not a mysterious DKIM failure. It is usually a damaged DNS value: one missing character, one extra quote, a copied line break, a truncated paste, or a DNS migration that changed the long TXT value.
The fix is direct. Get the original DKIM public key from the system that signs mail for the domain, republish that exact value at the selector hostname, wait for DNS to update, then test a real message. I do not rotate every key immediately when I see this error. I first compare the published p= value against the expected key, because a one-character paste error is enough to break validation.

What the error means

DKIM works by placing a signature in the message header and publishing the matching public key in DNS. The receiver reads the selector from the DKIM-Signature header, looks up the TXT record at a name like selector._domainkey, then decodes the public key in the p= tag. If the receiver cannot decode that public key, it cannot verify the signature.
A message such as bad base64 decode tells me the problem appears before signature verification. The validator has not reached the point of deciding whether the message body changed. It failed while trying to convert the DNS text into a usable RSA key.

Fast diagnosis

If the p= string has an odd length, illegal characters, spaces copied from a display format, or a missing middle character, base64 decoding fails. The answer is to republish the original public key, not to edit the string by hand.
This is different from a DKIM signature mismatch. With a mismatch, the DNS public key is readable, but the signature does not match the signed headers or body. With an invalid RSA public key, the public key itself is unreadable or not an RSA key.

Invalid public key

  1. Failure point: The DNS value cannot be decoded into a usable RSA public key.
  2. Usual cause: The long TXT value was truncated, altered, wrapped, or copied with extra characters.
  3. Best fix: Replace the entire public key with the original value from the signing system.

Signature mismatch

  1. Failure point: The key loads, but the message signature does not validate.
  2. Usual cause: A mail gateway, footer, relay, or signer change altered signed content.
  3. Best fix: Inspect the signed message path and verify the final message after all modifications.

The common causes

When I troubleshoot this, I start with the assumption that the DNS record changed. DKIM public keys are long, and DNS control panels display long TXT records in different ways. A record that was valid in the old DNS interface can be broken when someone copies the displayed value into a new provider.
  1. Missing character: A single lost character in the middle of p= makes the base64 string invalid or changes the decoded bytes.
  2. Truncated paste: The DNS form accepts only part of the value, or the operator copies only one visible segment.
  3. Bad wrapping: A text editor inserts a carriage return or newline inside the key during copying.
  4. Copied quotes: The record is copied from a quoted display format, and the quotes become part of the DNS value.
  5. Wrong selector: The sender signs with one selector, but DNS has an old or unrelated public key at that hostname.
  6. Wrong key type: The record says k=rsa, but the value is not an RSA public key.
The odd-length clue is useful. Base64 data is encoded in four-character groups after padding rules are applied. Public keys in DKIM records normally have a length that fits those rules. If the visible p= value is 215 characters, for example, I treat that as evidence of a missing or extra character and compare it to the expected key.

DKIM public key sanity checks

Quick signals that help separate a damaged key from a normal DKIM TXT record.
Odd p length
Bad
Strong signal of a missing or extra character.
Quoted chunks
Check
Normal in zone file format if DNS joins them correctly.
1024-bit key
Old
Often still accepted, but rotation to 2048-bit is better.
2048-bit key
Good
Common modern choice when DNS provider support is clean.
DNS provider limits are another common source of confusion. TXT records can be split into multiple quoted strings in a zone file, but the returned DNS answer should be one joined value. If a provider stores the chunks incorrectly, or if someone copies the visible chunks into another provider with the quote marks and spaces included, DKIM breaks. This related guide on DNS TXT limits goes deeper into that specific failure mode.

How to fix it

Fix the record by replacing the whole public key. Do not try to guess the missing character. Do not paste around the broken part. A DKIM public key is generated by the signing system, and the public DNS record must match that generated value exactly.
  1. Find selector: Open a failing message and read the s= and d= values in the DKIM signature.
  2. Get source key: Copy the public key from the mail platform, MTA, or signing service that owns that selector.
  3. Replace record: Update the TXT record at the exact selector hostname and paste the complete value.
  4. Preserve value: Use the provider's TXT field format, but keep the actual key characters unchanged.
  5. Retest mail: Send a new message after DNS propagation and inspect the authentication result.
Valid split DKIM TXT record exampledns
selector1._domainkey.example.com. 300 IN TXT ( "v=DKIM1; k=rsa; " "p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwY5m8z" "mM6B6mQ2soC2CxL6nq2r31K09vJxJ9ZtqP0eF4xXq" "nZ9u8b9Dg4k8nQIDAQAB" )
The quoted split above is normal zone-file presentation. DNS does not return the quote marks as part of the key. In many web DNS panels, though, the right input is a single TXT value, not a zone-file style block. That mismatch is where many DKIM records get damaged.

Do not patch the key manually

If one character is missing, adding a random base64 character only creates a different invalid or wrong key. The correct repair is to retrieve the original public key or generate a new key pair and publish the new public key.
If the signing system no longer shows the old key, generate a new DKIM key pair, publish the new public key, and switch the sender to sign with the new selector. Keep the old selector in DNS during a short overlap if old mail still needs to validate.

Validate the key before changing more DNS

After republishing the record, validate the selector itself before touching DMARC policy or sender configuration. A clean key lookup tells you that the DNS value can be decoded and parsed. It does not prove every outbound message is signed correctly, but it removes the public key as the failure point.
A focused DKIM checker is useful here because you can test the selector and domain without waiting for a new campaign or automated send. If the selector passes but messages still fail, move to message-level troubleshooting.

DKIM checker

Check selector records and public key configuration.

?/7tests passed
If the checker says the selector has no record, verify the hostname. A DKIM TXT record lives under _domainkey, and a single missing label changes the lookup entirely. The troubleshooting path for a no DKIM record error is related, but the fix is different because DNS lookup fails before key parsing starts.
Flowchart showing how to find, decode, replace, and retest a DKIM public key.
Flowchart showing how to find, decode, replace, and retest a DKIM public key.
Once the selector validates, send a fresh test message. Check whether DKIM passes, whether the signing domain matches the domain you expected, and whether DMARC gets either SPF or DKIM domain match. A valid key fixes only the DNS key parsing problem. It does not fix unsigned mail, wrong signing domains, body hash failures, or forwarding changes.

What to check in the DNS record

The DKIM TXT record is a tag-value list. The public key sits in p=, and the rest of the record gives receivers context. Most broken RSA public key errors come down to the p= tag, but I still check the whole TXT value because surrounding syntax can hide the real mistake.

Item

Good

Problem

Version
v=DKIM1
Missing tag
Type
k=rsa
Wrong key
Key
p=...
Broken text
Host
selector
Wrong name
Compact DKIM TXT record checks.
If the record has multiple TXT values at the same selector, clean that up as well. DKIM selectors should not publish competing keys for the same hostname. Receivers can treat multiple records as invalid, and the failure will look inconsistent across mailbox providers.
Broken DKIM TXT record patternstext
v=DKIM1; k=rsa; p=MIIBIjANBgkq...IDAQAB" v=DKIM1; k=rsa; p=MIIBIjAN BgkqhkiG9...IDAQAB v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9...IDAQA
Those examples show an extra quote, an inserted space, and a truncated ending. The exact visible error varies by validator, but the repair remains the same: replace the key with the clean source value.

Prevent the same failure

The best prevention is to stop treating DKIM TXT records as casual copy-paste text. Long keys need a repeatable change process, especially when moving DNS providers or rotating keys across many domains.
  1. Store source: Keep the generated DKIM record from the signing platform in a controlled ticket or change log.
  2. Copy raw: Copy from the provider's raw record value, not a wrapped display view.
  3. Avoid editors: Do not use word processors or editors that auto-wrap, quote, or reformat text.
  4. Test selector: Validate the selector immediately after DNS changes and again after propagation.
  5. Monitor mail: Watch real authentication results after the DNS record looks valid.
For one domain, this is manageable with a careful checklist. For many domains, a platform matters. Suped is built for this workflow: it brings together DMARC, SPF, DKIM, blocklist (blacklist) monitoring, deliverability insights, and real-time alerts in one place. Suped also gives automated issue detection and concrete steps to fix authentication failures, which helps teams avoid staring at raw aggregate reports.
DMARC record detail view showing SPF, DKIM, DMARC, rDNS diagnostics, and DNS records
DMARC record detail view showing SPF, DKIM, DMARC, rDNS diagnostics, and DNS records
For most teams, Suped is the best overall DMARC platform when the need is ongoing authentication control rather than a one-off lookup. The practical reason is scope: DKIM record validation is one piece, but the real operational work includes DMARC policy staging, SPF lookup limits, Hosted SPF, Hosted DMARC, Hosted MTA-STS, blocklist (blacklist) monitoring, and alerts when authentication failure rates change.
If you need a broader DNS and authentication snapshot, run a domain health checker after the DKIM record passes. If the domain sends meaningful business email, ongoing DMARC monitoring is the better long-term control because it shows which sources are passing, failing, or sending without authorization.

Views from the trenches

Best practices
Compare the DNS key against the source key before rotating selectors or changing mail flow.
Validate the selector after every DNS migration, especially when records were copied manually.
Keep DKIM record copies in change tickets so later DNS edits can be checked byte for byte.
Send a fresh test message after DNS passes because message signing can still fail later.
Common pitfalls
Copying wrapped TXT records from one DNS panel can insert quotes, spaces, or newlines.
Fixing only the visible error often misses a wrong selector or stale key at the same host.
Assuming a valid DNS lookup proves DKIM passes skips the need to test a real message.
Letting old selectors linger without notes makes future key comparisons slower and risky.
Expert tips
Treat odd-length public keys as paste-damage evidence and fetch the original value again.
Use a new selector when the original key source is gone, then monitor both during overlap.
Check for multiple TXT records at the selector before chasing message-level DKIM failures.
During DNS moves, export raw zone data and avoid copying from formatted browser displays.
Marketer from Email Geeks says bad base64 decode usually means the DKIM public key was malformed before any message signature check happened.
2024-01-26 - Email Geeks
Marketer from Email Geeks says an odd-length key is a useful clue because long base64 values often break when a character is missed.
2024-01-26 - Email Geeks

The practical takeaway

Invalid RSA public key errors in DKIM records come from the DNS key value, not from DMARC policy and usually not from the message content. The receiver cannot decode the public key in p=, so it cannot use that key to verify any signature.
The clean repair is to republish the complete original public key or rotate to a new selector if the original key is unavailable. After that, validate the selector, send a new message, and monitor authentication results. That sequence keeps the fix narrow and prevents unnecessary changes to SPF, DMARC, or mail routing.

Frequently asked questions

DMARC monitoring

Start monitoring your DMARC reports today

Suped DMARC platform dashboard

What you'll get with Suped

Real-time DMARC report monitoring and analysis
Automated alerts for authentication failures
Clear recommendations to improve email deliverability
Protection against phishing and domain spoofing
    What causes invalid RSA public key errors in DKIM records and how can I fix it? - Suped