Skip to content
ecdsa.com
jsonwebtoken (Node.js)JWT libraries

Error message

invalid signature

What it means

The token parsed fine and its structure is valid, but the cryptographic check failed: the signature over header.payload does not verify against the key you supplied. Either the key is not the one that signed the token, or the signed bytes changed after signing.

Why it happens

How to fix it

  1. 1.

    Fingerprint the key on both sides

    Hash the public key the verifier actually loaded and compare it with the issuer's. Different fingerprints mean a stale or wrong key — the most frequent cause by far — and end the search in one step.

    js
    import { createHash, createPublicKey } from "node:crypto";
    
    // Run on the verifier, and on the issuer with its signing key: the outputs must match.
    const spki = createPublicKey(process.env.JWT_PUBLIC_KEY).export({ type: "spki", format: "der" });
    console.log(createHash("sha256").update(spki).digest("hex"));
  2. 2.

    Match the token's kid to the verifying key

    Decode the header without verifying and compare its kid with the key you hold. If the issuer publishes a JWKS, resolve the key by kid instead of hard-coding one.

    js
    const { header } = jwt.decode(token, { complete: true });
    console.log(header.kid, header.alg); // compare with your JWKS / configured key
  3. 3.

    Let the debugger name the mismatch

    Paste the token and public key into the JWT debugger: it verifies ES256/ES384/ES512 locally and distinguishes wrong key, tampered payload and malformed signature encoding instead of a bare boolean.

Related errors

Browse the full signature error database