You push a fresh PHP or Laravel build to staging, trigger a login request, and your error log fills up with openssl_pkey_get_private(): key values mismatch, Unable to read key from file, or error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt. Everything worked on your local machine — so why is OpenSSL suddenly rejecting your private key?
Why Debugging Key Errors via Random Online Tools Is Risky
When a production deployment breaks at midnight, it is tempting to paste your private.pem and .env passphrase into the first online PEM checker that pops up. Most of those sites post both your key and passphrase directly to a backend server. Even a single leak forces an emergency key rotation and invalidates every active user session.
Bramhify's Encrypted Private Key Decryptor lets you isolate passphrase, encoding, and key-pair mismatches 100% locally in your browser via the native Web Crypto API — zero uploads, zero cookies, and instant memory wiping.
Encrypted Private Key Decryptor:

Verify whether your PEM passphrase actually decrypts the key and inspect its derived SHA-256 public key fingerprint offline.
Try the 100% browser-local tool: Encrypted Private Key Decryptor on Bramhify — zero uploads, zero tracking, runs entirely in your browser.
The 5 Most Common Causes of bad decrypt in PHP, Laravel & Symfony
1. Unquoted $ Characters in .env Files (The #1 Silent Killer)
In vlucas/phpdotenv (used by Laravel) and Symfony Dotenv, double-quoted or unquoted strings containing $ trigger variable interpolation. If your passphrase is my$ecret#2026:
# BROKEN — $ecret is expanded to an empty string! JWT_PASSPHRASE=my$ecret#2026 # FIXED — single quotes prevent variable & comment expansion JWT_PASSPHRASE='my$ecret#2026' Also watch for # characters: an unquoted # starts an inline comment in .env, silently truncating the rest of your passphrase!
2. Escaped \n Line Breaks in Docker / Cloud Secrets
When injecting an entire PEM key through an environment variable (OAUTH_PRIVATE_KEY), CI/CD pipelines often escape newlines as literal \n characters. OpenSSL rejects single-line PEM strings unless you restore real line breaks first:
$pem = str_replace('\n', "\n", trim($_ENV['JWT_PRIVATE_KEY'])); $key = openssl_pkey_get_private($pem, $_ENV['JWT_PASSPHRASE']); 3. Mismatched Public Key & Private Key Pairs
Sometimes the passphrase is right, but public.pem on the API gateway came from an older key rotation. Token signing succeeds, yet every downstream verification fails with Invalid signature.
4. Legacy 3DES / OpenSSL 3.0 Legacy Provider Errors
PHP 8.2+ compiled against OpenSSL 3.x disables older ciphers like RC2 or 3DES by default. If your key was generated years ago with -des3, OpenSSL 3 throws unsupported or bad decrypt even with the right passphrase.
5. Trailing Spaces or Windows CRLF (\r\n) Inside Secret Managers
Copying a passphrase from a password manager or spreadsheet often sneaks a trailing space or newline into Kubernetes/AWS Secrets Manager.
Step-by-Step: Isolate the Bug in 30 Seconds Offline
Step 1: Test the Key + Passphrase Locally
Open the Encrypted Private Key Decryptor, paste your private.pem, and type the exact passphrase from your secret manager. Tap Decrypt Private Key.
Step 2: Interpret the Result Immediately
- Decryption succeeds: Your key and passphrase are 100% valid — the bug is inside
.envquoting ($/#), literal\nescaping, or file permissions (chmod 600on Laravel Passport keys). - Decryption fails: Double-check for trailing spaces, wrong environment secret, or legacy 3DES encoding (Bramhify explicitly tells you if the key uses unsupported 3DES or OpenSSH format).
Step 3: Verify the Derived Public Key Matches Your Config
Compare Bramhify's Derived Public Key (SPKI PEM) and SHA-256 Fingerprint against the public.pem deployed on your server. If they differ, replace your stale public key immediately or generate a clean new pair with our Public & Private Key Generator.
Step 4: Re-Encrypt to Modern PBES2 AES-256-CBC (Optional)
If your key uses legacy Proc-Type: 4,ENCRYPTED headers, copy the decrypted PKCS#8 PEM, switch to Encrypt Key (Lock) mode, and export a fresh OpenSSL 3-compatible BEGIN ENCRYPTED PRIVATE KEY (PBKDF2-SHA256 + AES-256-CBC). Then tap Wipe Memory.
OpenSSL & PHP Error Code Diagnostic Matrix
| Error Message in PHP / Laravel Logs | Exact Cause | Fastest Fix |
|---|---|---|
EVP_DecryptFinal_ex:bad decrypt | Wrong passphrase, unquoted $/# in .env, or trailing whitespace | Single-quote JWT_PASSPHRASE='...' and verify offline in Bramhify |
PEM routines:get_name:no start line | Literal \n in env var, truncated PEM, or missing -----BEGIN line | Replace \n with actual newlines or mount the .pem file directly |
OSSL_DECODER_from_bio:unsupported | Legacy 3DES or RC2 encrypted key on PHP 8.2+ / OpenSSL 3.x | Re-encrypt to modern PBES2 AES-256-CBC with PBKDF2-SHA256 |
Key path is not readable / permissions | File permissions too open (0644) or wrong owner for www-data | Run chmod 600 private.pem && chown www-data:www-data private.pem |
Invalid signature on token verify | public.pem comes from a different key pair than private.pem | Derive fresh SPKI public.pem in Bramhify and compare SHA-256 fingerprints |
Production Key Hygiene Checklist
- Never commit
.pemor.keyfiles into Git — add*.pemand*.keyto.gitignore. - Store the
.pemfile outsidepublic/(for example,storage/keys/or mounted read-only via Docker/Kubernetes secrets). - Keep the passphrase in a separate secret store from the key file itself, and clear any cached Laravel config (
php artisan config:clear) immediately after updating.env.
Still seeing 401 Unauthorized after fixing the key? Inspect the signed token claims in our JWT & SD-JWT Decoder, or read How to Decrypt Encrypted PEM Private Keys Offline and PKCS#8 vs PKCS#1 vs JWK Key Formats.
Frequently Asked Questions (FAQs)
Why does openssl_pkey_get_private() return false with no exception?
PHP's OpenSSL extension returns false on key load failures instead of throwing by default. Always call openssl_error_string() immediately afterward in a loop to print the exact OpenSSL error queue (bad decrypt, no start line, or unsupported).
Does Laravel Passport require chmod 600 on oauth-private.key?
Yes. On Linux servers, league/oauth2-server (used by Laravel Passport) checks file permissions on storage/oauth-private.key and refuses overly permissive files like 0644 or 0777. Set chmod 600 storage/oauth-private.key owned by your PHP-FPM user.
Can this tool detect legacy OpenSSL Proc-Type: 4,ENCRYPTED keys generated by PHP?
Yes. Bramhify supports both modern PKCS#8 (BEGIN ENCRYPTED PRIVATE KEY) and legacy OpenSSL PEM (BEGIN RSA PRIVATE KEY / BEGIN EC PRIVATE KEY encrypted with AES-128-CBC or AES-256-CBC) and displays the exact detected cipher and KDF.
Is my production .env passphrase safe when tested in Bramhify?
Yes. Decryption runs completely inside your browser's volatile memory using Web Crypto with zero network requests and zero persistent storage.
Originally published on Bramhify Guides. Try the interactive 100% offline browser utility directly at bramhify.com.
