Node.js cannot parse a private key and reports DECODER routines unsupported
Fix it fast
Most common cause, 1 of 3The PEM text lost its line breaks inside an environment variable
Next.js turns \n into a line break only inside a double-quoted .env value, so quote the value that way or let the key span real lines.
# .env.local: double quotes, so \n becomes a real line break
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEv...\n-----END PRIVATE KEY-----\n"
// in code, before the key is first used
const privateKey = process.env.PRIVATE_KEY.replace(/\\n/g, '\n');Short answer
error:1E08010C:DECODER routines::unsupported (ERR_OSSL_UNSUPPORTED) means OpenSSL inside Node.js 22, 24 or 26 could not read the key you passed in any format it knows. Usually the PEM lost its line breaks in an environment variable, the file is an OpenSSH-format key, or DER bytes went in without format: 'der'. Print the key's first characters to see which.
Which cause do you have?
Print the start of the key exactly as your process receives it, together with a count of real line breaks and of the two-character sequence backslash-n. Replace PRIVATE_KEY with your own variable name. Escaped sequences or zero line breaks mean cause 1, an OPENSSH header means cause 2, and binary noise or no BEGIN line means cause 3.
node -e 'const k = process.env.PRIVATE_KEY || ""; console.log(JSON.stringify(k.slice(0, 40)), "| line breaks:", k.split("\n").length - 1, "| literal \\n:", k.split("\\n").length - 1)'Then find the line you see in this list and open its fix:
- 1The PEM text lost its line breaks inside an environment variable
The first step prints \n between the dashes and the base64, and the line-break count is zero - 2The key file uses OpenSSH's own private key format
The first line of the file is -----BEGIN OPENSSH PRIVATE KEY----- - 3Binary DER or a bare base64 body is passed as if it were PEM
The value has no BEGIN line: either raw bytes from a .der file, or a long base64 run copied without its header and footer
What does the error look like?
Error: error:1E08010C:DECODER routines::unsupportedlibrary: 'DECODER routines', reason: 'unsupported', code: 'ERR_OSSL_UNSUPPORTED'
Cause 1 of 3
The PEM text lost its line breaks inside an environment variable
You seeThe first step prints \n between the dashes and the base64, and the line-break count is zero
Check
Node.js reports error:1E08010C DECODER routines::unsupported when the PEM string it gets has backslash-n pairs where newlines should be. Hosting dashboards, single-quoted .env values and CI secret fields keep those two characters as typed. Node.js treats any string key as PEM, OpenSSL cannot find a PEM block in that text, and the decoder gives up. Look at how the value is written in your env files.
grep -n "PRIVATE KEY" .env .env.local 2>/dev/nullFix
Next.js turns \n into a line break only inside a double-quoted .env value, so quote the value that way or let the key span real lines. Where you cannot control quoting, put the whole service-account JSON in one variable and JSON.parse it, or turn the escapes back into newlines once at start-up.
# .env.local: double quotes, so \n becomes a real line break
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEv...\n-----END PRIVATE KEY-----\n"
// in code, before the key is first used
const privateKey = process.env.PRIVATE_KEY.replace(/\\n/g, '\n');Verify
createPrivateKey accepts the string and prints the key type, usually rsa for Google and GitHub App keys.
node -e 'const k = process.env.PRIVATE_KEY.replace(/\\n/g, "\n"); console.log(require("node:crypto").createPrivateKey(k).asymmetricKeyType)'Confirmed by github.com
Cause 2 of 3
The key file uses OpenSSH's own private key format
You seeThe first line of the file is -----BEGIN OPENSSH PRIVATE KEY-----
Check
ssh-keygen writes newly generated private keys in OpenSSH's own container unless told otherwise. That file works for ssh, but createPrivateKey reads only PEM, DER, JWK or raw key material, so the same DECODER error appears even though nothing is wrong with the key itself.
head -n 1 ~/.ssh/id_rsaFix
Work on a copy and rewrite an RSA or ECDSA key as PKCS#8 with the passphrase-change option, which converts the file format without changing the key. The man page limits PEM and PKCS8 output to supported key types; when the header still says OPENSSH afterwards (an Ed25519 key, for example), create a fresh PKCS#8 key in Node.js and register its public half where the old key was used.
cp ~/.ssh/id_rsa ./signing-key.pem
ssh-keygen -p -m PKCS8 -f ./signing-key.pem
head -n 1 ./signing-key.pem # -----BEGIN PRIVATE KEY-----
# if the header is unchanged, make a new key in a format Node.js reads
node -e 'const { generateKeyPairSync } = require("node:crypto"); const { privateKey } = generateKeyPairSync("ed25519"); process.stdout.write(privateKey.export({ format: "pem", type: "pkcs8" }))' > ed25519-key.pemVerify
The header now reads BEGIN PRIVATE KEY, and loading the file prints a key type instead of throwing.
node -e 'console.log(require("node:crypto").createPrivateKey(require("node:fs").readFileSync("signing-key.pem")).asymmetricKeyType)'Confirmed by man.openbsd.org
Cause 3 of 3
Binary DER or a bare base64 body is passed as if it were PEM
You seeThe value has no BEGIN line: either raw bytes from a .der file, or a long base64 run copied without its header and footer
Check
For a string or Buffer, Node.js assumes the format is PEM. DER input has to come with format 'der' and a type ('pkcs8', 'pkcs1' for RSA only, 'sec1' for EC only), or the decoder rejects it. A base64 body whose header and footer were stripped is neither PEM nor DER until you decode it. Dump the first bytes to see whether the file is text or binary.
head -c 32 private-key.der | od -c | head -n 2Fix
Turn a base64 body into bytes first, then hand the bytes over as DER with the type that matches the original header: BEGIN PRIVATE KEY is pkcs8, BEGIN RSA PRIVATE KEY is pkcs1, BEGIN EC PRIVATE KEY is sec1.
const { createPrivateKey } = require('node:crypto');
// base64 body only, without the BEGIN and END lines
const der = Buffer.from(process.env.PRIVATE_KEY_B64, 'base64');
const key = createPrivateKey({ key: der, format: 'der', type: 'pkcs8' });Verify
A signature now comes back from the key object; for a 2048-bit RSA key it is 256 bytes long.
node -e 'const c = require("node:crypto"); const k = c.createPrivateKey({ key: Buffer.from(process.env.PRIVATE_KEY_B64, "base64"), format: "der", type: "pkcs8" }); console.log(c.sign("sha256", Buffer.from("ping"), k).length)'Confirmed by nodejs.org
How do I stop it coming back?
- Parse every signing key with createPrivateKey when the process boots, so a mangled secret stops the deploy instead of the first API call.
- Write the expected first line of each key (for example BEGIN PRIVATE KEY) next to its variable in your env template.
- Export keys meant for Node.js services as PKCS#8 PEM at creation time rather than reusing ssh keys.
- Mount keys as files from your secret manager where the platform allows it, which keeps line breaks intact.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.