0X8009310D

ASN1 (0X8009310D) - Bad Encoding Rule: Quick Fix That Works

Cybersecurity & Malware Intermediate 👁 8 views 📅 May 26, 2026

This error means a certificate's encoding is broken. Fix it by reimporting the cert with correct format or regenerating it. Real fix below.

First, the Fix That Works

You've got the 0X8009310D error when trying to import a certificate, right? That's an ASN1 bad encoding rule error. It means the file you're trying to import isn't properly formatted. Here's what actually works—I've done this for half a dozen small businesses this year alone.

  1. Open the certificate file in a text editor (Notepad is fine). Look for the header. If it says -----BEGIN CERTIFICATE-----, it's PEM format. If it starts with random binary garbage, it's DER. Most Windows tools want DER for some operations, PEM for others. This error usually hits with PEM converted badly.
  2. Use certutil to convert it. Open Command Prompt as Administrator. Run this:
    certutil -decode badcert.pem fixedcert.cer
    This strips the PEM headers and gives you a clean DER file. Then try importing fixedcert.cer.
  3. If that fails, try the reverse. Some apps need PEM. Convert DER to PEM:
    certutil -encode badcert.cer fixedcert.pem
    Then import the .pem file using the Certificate Import Wizard or certmgr.msc.
  4. Still busted? The cert might be corrupted. Regenerate it from the original CA. If it's a self-signed cert, use openssl x509 -in badcert.cer -inform DER -out goodcert.cer -outform PEM (or swap DER/PEM).

Why This Fix Works

The 0X8009310D error is thrown by the Microsoft CryptoAPI when it encounters malformed ASN.1 data. ASN.1 is the encoding standard for X.509 certificates. When you export a certificate from one system (especially a Linux box, a Java keystore, or an old Cisco device), the headers, line breaks, or trailing data often get mangled. Windows is picky—it expects strict DER encoding inside the PEM wrapper. A single extra space or wrong line ending triggers this error.

I had a client last month whose print queue server wouldn't accept a renewed SSL cert. The vendor sent a .p7b (PKCS#7) file with embedded certificates. When exported as a .cer from that collection, it had an extra null byte at the end. certutil fixed it in 20 seconds.

The conversion step using certutil or openssl re-encodes the certificate properly, stripping artifacts and ensuring the ASN.1 structure is valid. It's the same reason you can't just rename a file extension and expect it to work—the internal data needs to match the expected schema.

Less Common Variations

Sometimes the error appears in these situations:

  • In Event Viewer (Event ID 4107 or 4108) linked to the Certificate Propagation service. Happens when a root cert is corrupt. Fix: delete and reimport from a clean source.
  • With IIS or Exchange when binding a certificate. The cert chain might have a bad intermediate. Use certlm.msc to check each cert in the chain. Right-click, Open, verify the “Issued to” and “Valid from” dates. If one shows “This certificate has an invalid signature,” it's the ASN1 encoding issue.
  • With .PFX files that include private keys. The PFX is a PKCS#12 container—it can have ASN.1 errors too. Export the cert part only: openssl pkcs12 -in bad.pfx -nokeys -out cert.pem, then convert back to a clean PFX: openssl pkcs12 -export -in cert.pem -inkey key.pem -out clean.pfx.
  • On older Windows Server 2008 R2 or 2012. Those systems have stricter ASN.1 parsers. I've seen certs work fine on Windows 10 but fail on Server 2012 with this exact error. Same fix applies.

Prevention Tips

To avoid hitting 0X8009310D again:

  1. Always export certificates as Base-64 encoded X.509 (.CER) from the source system. That's the PEM format. Avoid DER unless you know the target system needs it.
  2. Use one tool for all cert management. I stick with OpenSSL for conversions—it handles the encoding properly. Then I import to Windows. Mixing tools (like copying from Java keytool to Windows Cert Manager) introduces formatting issues.
  3. Test the cert on a non-production machine first. Import it there, try to use it. If you get the error, fix it before touching the live server.
  4. Keep the original signing request (CSR) and CA response. If you need to regenerate, you have a clean starting point. Without those, you're stuck reverse-engineering a broken file.
  5. Check the file size. A valid single certificate in PEM format is usually around 1-2 KB. If it's 500 bytes or 50 KB, something's off.

If you've got a cert that won't import after all this, post the first 100 characters of the file (obfuscate the serial number) in the comments. I'll tell you what's wrong. But 90% of the time, a simple format conversion using certutil or openssl is all you need.

Was this solution helpful?