Home >Blog

Fix "PEM Certificate Is Invalid" Error: Common Causes and Solutions

Published Updated

"PEM certificate is invalid" is one of the most common TLS deployment errors, and it's almost never a security problem — it's a file format problem. The certificate data is fine; the way it's stored or pasted is broken. Here's how to fix it in a few minutes.

The symptom

Your web server, load balancer, or openssl command refuses to load a certificate file, usually with "unable to load certificate" or "PEM routines:CRYPTO_internal:bad decrypt".

Common causes

  • Wrong format: you saved a DER file as .pem. PEM is base64 text with BEGIN/END lines; DER is raw binary.
  • Missing or mangled header/footer. PEM must start with -----BEGIN CERTIFICATE----- and end with -----END CERTIFICATE-----.
  • Broken chain: cert files pasted out of order. A full chain is root + intermediate + leaf, with the leaf first.
  • Extra whitespace or hidden characters. A stray space or newline mid-base64 breaks the decoder.
  • Password-protected private key. Without the passphrase, loading fails.

Fix it, one step at a time

1. Identify the format

Run file certificate.pem and head -c 100 certificate.pem. If you see binary, it's DER. If you see base64 with header lines, it's PEM.

2. Convert DER to PEM

openssl x509 -inform der -in cert.der -out cert.pem

3. Rebuild a clean PEM file

# Leaf first, then intermediates, then root
cat leaf.pem intermediate.pem root.pem > fullchain.pem
openssl verify -untrusted intermediate.pem -CAfile root.pem fullchain.pem

4. Strip stray whitespace

openssl x509 -in cert.pem -out clean.pem

OpenSSL re-emits a canonical PEM, dropping stray spaces.

5. Handle a password-protected key

# Remove passphrase (make a secure copy first)
openssl rsa -in encrypted.key -out decrypted.key

6. Verify before deploying

openssl x509 -in cert.pem -noout -text | head -20
openssl x509 -in cert.pem -noout -checkend 0
Side-by-side of a correct PEM block and a broken one with missing header

If the file still fails, paste it into the SSL Certificate Decoder — it will show you exactly which field or line is malformed.

Is this error dangerous?
It just means the file isn't loadable as a certificate. Usually it's a format problem, not a security issue — but do fix it before deployment.

What's the difference between PEM and DER?
DER is binary; PEM is the base64 text version with header/footer lines. Same certificate, different packaging.

Why would my key be password-protected?
If the private key was created with a passphrase, OpenSSL won't load it without the password.

Does this affect my whole site?
Only if the broken file is what your server loads. Fix the format, then reload the service.

FAQ

Is this error dangerous?
It just means the file isn't loadable as a certificate. Usually it's a format or formatting problem, not a security issue — but do fix it before deployment.
What's the difference between PEM and DER?
DER is binary; PEM is the base64 text version with header/footer lines. They're the same certificate, different packaging.
Why would my key be password-protected?
If the private key was created with a passphrase, OpenSSL won't load it without the password. Use -passin or remove the passphrase if you must.
Does this error affect my whole site?
Only if the broken file is what your web server loads. The fix is to correct the file format, then reload the service.

Table of Contents

Information

  • Hits17
  • Published date2026/09/30
0/500
Share your thoughts respectfully.

More Posts

Explore more articles from this section
How to Decode an SSL Certificate Online
Aug 24, 202647views

How to Decode an SSL Certificate Online

Learn how to decode an SSL certificate online by pasting PEM text or uploading a certificate, then review the ...

#ssl certificate#certificate decoder#PEM#TLS
How to Read SSL Certificate Details: A Practical Guide to Subject, Issuer, CN, SAN, and Fingerprints
Aug 27, 202639views

How to Read SSL Certificate Details: A Practical Guide to Subject, Issuer, CN, SAN, and Fingerprints

Learn how to use SSL Certificate Decoder to inspect a public certificate and understand Subject, Issuer, Commo...

#SSL certificate#certificate details#Subject#Issuer
Online Certificate Decoder: Supported Formats and Certificate Details
Sep 20, 202631views

Online Certificate Decoder: Supported Formats and Certificate Details

A browser-based X.509 certificate decoder that parses PEM, CRT, CER, and DER files and shows issuer, subject, ...

#certificate decoder online#X.509#PEM#SSL certificate
How to Check an SSL Certificate Fingerprint
Sep 08, 202630views

How to Check an SSL Certificate Fingerprint

Learn how to use SSL Certificate Decoder to read SHA-256 and SHA-1 certificate fingerprints, copy a fingerprin...

#SSL certificate fingerprint#SHA-256 fingerprint#SHA-1 fingerprint#certificate fingerprint checker
How to Decode a PEM Certificate Online with SSL Certificate Decoder
Aug 30, 202630views

How to Decode a PEM Certificate Online with SSL Certificate Decoder

Learn how PEM boundary markers work and how to decode a public PEM certificate by pasting it or uploading a PE...

#pem certificate decoder#PEM certificate#BEGIN CERTIFICATE#END CERTIFICATE
How to Compare Two SSL Certificates
Sep 14, 202626views

How to Compare Two SSL Certificates

A practical guide to comparing two SSL/TLS certificates: subject and issuer, validity period, key strength, su...

#compare ssl certificates#ssl certificate comparison#openssl compare certificates#x509 compare
Feedback email