{"record":{"id":"e79841107c16c572","repo":"lcobucci/jwt","slug":"key-provided-is-shorter-than-expectedlength-bits-only-rsa","errorCode":null,"errorMessage":"Key provided is shorter than {expectedLength} bits, only {actualLength} bits provided","messagePattern":"Key provided is shorter than (.+?) bits, only (.+?) bits provided","errorType":"exception","errorClass":"Lcobucci\\JWT\\Signer\\InvalidKeyProvided","httpStatus":null,"severity":"error","filePath":"src/Signer/Rsa.php","lineNumber":32,"sourceCode":"        return $this->createSignature($key, $payload);\n    }\n\n    final public function verify(string $expected, string $payload, Key $key): bool\n    {\n        return $this->verifySignature($expected, $payload, $key);\n    }\n\n    final protected function guardAgainstIncompatibleKey(int $type, int $lengthInBits): void\n    {\n        if ($type !== OPENSSL_KEYTYPE_RSA) {\n            throw InvalidKeyProvided::incompatibleKeyType(\n                self::KEY_TYPE_MAP[OPENSSL_KEYTYPE_RSA],\n                self::KEY_TYPE_MAP[$type] ?? 'unknown',\n            );\n        }\n\n        if ($lengthInBits < self::MINIMUM_KEY_LENGTH) {\n            throw InvalidKeyProvided::tooShort(self::MINIMUM_KEY_LENGTH, $lengthInBits);\n        }\n    }\n}\n","sourceCodeStart":14,"sourceCodeEnd":36,"githubUrl":"https://github.com/lcobucci/jwt/blob/375813049c24c7111bda8b6884c57b071ceb2fe7/src/Signer/Rsa.php#L14-L36","documentation":"Thrown by Rsa::guardAgainstIncompatibleKey when the RSA key's bit length is below MINIMUM_KEY_LENGTH (the library's floor for secure RSA, commonly 384/512 bits depending on version). Short RSA keys are rejected to prevent trivially weak signatures.","triggerScenarios":"Signing or verifying with an RSA key shorter than the configured minimum (e.g. a 512- or 1024-bit test key when the minimum is higher), loaded via RsaSha256::create()->sign() with InMemory::file()/plainText PEM.","commonSituations":"Legacy keys generated long ago at 1024 bits, quick test keys generated with tiny sizes, library upgrades raising the minimum length, keys generated with `openssl genrsa 512`.","solutions":["Generate a new RSA key of at least 2048 bits: `openssl genrsa -out private.pem 2048`","Derive the matching public key: `openssl rsa -in private.pem -pubout -out public.pem`","Check the deployed key's size: `openssl rsa -in private.pem -noout -text | head -1`","If you must keep the old key, confirm the library version's MINIMUM_KEY_LENGTH and rotate anyway (short keys are insecure)"],"exampleFix":"// before\n$ openssl genrsa -out private.pem 512\n// after\n$ openssl genrsa -out private.pem 2048","handlingStrategy":"validation","validationCode":"$details = openssl_pkey_get_details(openssl_pkey_get_private(file_get_contents($pem))); if ($details['bits'] < 2048) { throw new RuntimeException('RSA key too short: ' . $details['bits'] . ' bits'); }","typeGuard":null,"tryCatchPattern":"try { $signature = $signer->sign($payload, $key); } catch (\\Jose\\Component\\Signature\\Exception\\InvalidKeyProvided $e) { /* weak key length; rotate key */ }","preventionTips":["Use >= 2048-bit RSA keys for all new deployments","Check key length during deployment scripts","Rotate legacy short keys proactively; upgrades may raise the minimum"],"tags":["rsa","weak-key","security","key-length"],"backgroundTag":"value-out-of-range","analyzedSha":"375813049c24c7111bda8b6884c57b071ceb2fe7","analyzedAt":"2026-09-14T11:12:28.004Z","contentChangedAt":"2026-09-14T11:12:28.004Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}