lcobucci/jwt · error · Lcobucci\JWT\Signer\Ecdsa\ConversionFailed
Invalid data. Should contain an integer.
Error message
Invalid data. Should contain an integer.
What it means
Thrown by the private readAsn1Integer helper when, while parsing a DER ECDSA signature inside fromAsn1, the next byte is not the ASN.1 INTEGER tag (0x02). A valid DER signature is a SEQUENCE of exactly two INTEGERs (r and s); anything else means the data is malformed.
Solutions
- Verify the input is a DER ECDSA signature (SEQUENCE of two INTEGERs), not another DER structure
- Check the signature was not truncated or modified in transit
- Confirm you are not passing a certificate or public key where a signature is expected
- Regenerate the signature from the original signer
Example fix
// before $raw = $converter->fromAsn1($derPublicKeyPemBody, 32); // wrong input // after $raw = $converter->fromAsn1($derSignature, 32);
Defensive patterns
Strategy: try-catch
Try / catch
try { $raw = $converter->fromAsn1($der, $length); } catch (\Jose\Component\Signature\Exception\ConversionFailed $e) { return false; /* invalid signature input */ } Prevention
- Sanitize signature input at the boundary (length + DER tag checks)
- Never pass certificates or keys into signature converters
- Treat conversion failure as an invalid-token signal in verification paths
When it happens
Trigger: Calling fromAsn1() with a DER blob whose SEQUENCE contents are not two INTEGER elements — e.g. corrupted data, wrong ASN.1 structure (e.g. a certificate or public key passed instead of a signature), or data truncated mid-sequence.
Common situations: Passing a DER public key or certificate instead of a DER signature, manually crafted ASN.1 payloads, or a bit-flip corruption during transmission.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Invalid data. Should start with a sequence.
- Invalid signature length.
- The type of the provided key is not
- The length of the provided key is different than
- The curve of the provided key is not
AI-assisted analysis of lcobucci/jwt@375813049c (2026-09-14).
Data as JSON: /api/errors/c9f780cd8b50a726.
Report an issue: GitHub.
Appendix: source
Thrown at src/Signer/Ecdsa/MultibyteStringConverter.php:129
$points = hex2bin(str_pad($pointR, $length, '0', STR_PAD_LEFT) . str_pad($pointS, $length, '0', STR_PAD_LEFT));
assert(is_string($points));
assert($points !== '');
return $points;
}
private static function readAsn1Content(string $message, int &$position, int $length): string
{
$content = substr($message, $position, $length);
$position += $length;
return $content;
}
private static function readAsn1Integer(string $message, int &$position): string
{
if (self::readAsn1Content($message, $position, self::BYTE_SIZE) !== self::ASN1_INTEGER) {
throw ConversionFailed::integerExpected();
}
$length = (int) hexdec(self::readAsn1Content($message, $position, self::BYTE_SIZE));
return self::readAsn1Content($message, $position, $length * self::BYTE_SIZE);
}
private static function retrievePositiveInteger(string $data): string
{
while (
substr($data, 0, self::BYTE_SIZE) === self::ASN1_NEGATIVE_INTEGER
&& substr($data, 2, self::BYTE_SIZE) > self::ASN1_BIG_INTEGER_LIMIT
) {
$data = substr($data, 2, null);
}
return $data;
}View on GitHub (pinned to 375813049c)