Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Security and hardening

Node.js cannot parse a private key and reports DECODER routines unsupported

Your error

Error: error:1E08010C:DECODER routines::unsupported1 more line it can show

Fix it fast

Most common cause, 1 of 3

The 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.

Fix
# .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');
Did this fix it?
Full steps for this cause: check, fix, verify

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.

  • Applies to Node.js 26.13 LTS, Node.js 24.22 LTS, Node.js 22.23, OpenSSL 3.5 bundled with Node.js
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
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:

  1. 1The PEM text lost its line breaks inside an environment variableThe first step prints \n between the dashes and the base64, and the line-break count is zero
  2. 2The key file uses OpenSSH's own private key formatThe first line of the file is -----BEGIN OPENSSH PRIVATE KEY-----
  3. 3Binary DER or a bare base64 body is passed as if it were PEMThe 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::unsupported
  • library: '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.

Check
grep -n "PRIVATE KEY" .env .env.local 2>/dev/null

Fix

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.

Fix
# .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.

Verify
node -e 'const k = process.env.PRIVATE_KEY.replace(/\\n/g, "\n"); console.log(require("node:crypto").createPrivateKey(k).asymmetricKeyType)'

Confirmed by github.com

Did this fix it?

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.

Check
head -n 1 ~/.ssh/id_rsa

Fix

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.

Fix
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.pem

Verify

The header now reads BEGIN PRIVATE KEY, and loading the file prints a key type instead of throwing.

Verify
node -e 'console.log(require("node:crypto").createPrivateKey(require("node:fs").readFileSync("signing-key.pem")).asymmetricKeyType)'

Confirmed by man.openbsd.org

Did this fix it?

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.

Check
head -c 32 private-key.der | od -c | head -n 2

Fix

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.

Fix
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.

Verify
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

Did this fix it?

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.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Workforce.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.