BookStackApp/BookStack · error · OidcInvalidKeyException
Key loaded from file path is not an RSA key as expected
Error message
Key loaded from file path is not an RSA key as expected
What it means
After successfully loading the key file, loadFromPath verifies the result is an RSA key (phpseclib RSA instance) since only RS256/RSA signing is supported. A successfully parsed but non-RSA key (e.g. EC, Ed25519) triggers this exception.
Source
Thrown at app/Access/Oidc/OidcJwtSigningKey.php:47
throw new OidcInvalidKeyException('Unexpected type of key value provided');
}
}
/**
* @throws OidcInvalidKeyException
*/
protected function loadFromPath(string $path): void
{
try {
$key = PublicKeyLoader::load(
file_get_contents($path)
);
} catch (\Exception $exception) {
throw new OidcInvalidKeyException("Failed to load key from file path with error: {$exception->getMessage()}");
}
if (!$key instanceof RSA) {
throw new OidcInvalidKeyException('Key loaded from file path is not an RSA key as expected');
}
$this->key = $key->withPadding(RSA::SIGNATURE_PKCS1);
}
/**
* @throws OidcInvalidKeyException
*/
protected function loadFromJwkArray(array $jwk): void
{
// 'alg' is optional for a JWK, but we will still attempt to validate if
// it exists otherwise presume it will be compatible.
$alg = $jwk['alg'] ?? null;
if ($jwk['kty'] !== 'RSA' || !(is_null($alg) || $alg === 'RS256')) {
throw new OidcInvalidKeyException("Only RS256 keys are currently supported. Found key using {$alg}");
}
// 'use' is optional for a JWK but we assume 'sig' where no value exists since that's whatView on GitHub (pinned to 18f8469a1c)
Solutions
- Generate/use an RSA key: openssl genrsa -out key.pem 2048
- If the IdP uses EC keys, switch the IdP to RS256 or obtain the RSA key/JWK
- Check the jwks/discovery output — this class only supports RSA/RS256 keys
- Re-export the key in RSA format if it was converted accidentally
Example fix
// before: EC key generated openssl ecparam -name prime256v1 -genkey -out key.pem // after: RSA key openssl genrsa -out key.pem 2048
Defensive patterns
Strategy: validation
Validate before calling
$details = openssl_pkey_get_details(openssl_pkey_get_public(file_get_contents($path)));
if (($details['type'] ?? null) !== OPENSSL_KEYTYPE_RSA) { throw new \RuntimeException('key is not RSA'); } Try / catch
try { $key = new OidcJwtSigningKey('file://' . $path); } catch (OidcInvalidKeyException $e) { if (str_contains($e->getMessage(), 'not an RSA key')) { /* swap in an RSA key or switch IdP to RS256 */ } throw $e; } Prevention
- Generate keys with openssl genrsa (RSA only — this library does not support EC/Ed25519)
- Keep IdP signing algorithm and local key type in sync (RS256)
- Document key requirements wherever keys are provisioned
When it happens
Trigger: new OidcJwtSigningKey('file://...') where the file parses as a valid key but of a non-RSA type, such as an EC private key or Ed25519 key.
Common situations: IdP migrated to ES256 and the configured key is EC; developer points at an SSH ed25519 key by mistake; key generated with openssl ecparam instead of genrsa.
Related errors
- Failed to load key from JWK parameters with error: {$excepti
- Unexpected type of key value provided
- Failed to load key from file path with error: {$exception->g
- An "e" parameter on the provided key is expected
- A "n" parameter on the provided key is expected
AI-assisted analysis of BookStackApp/BookStack@18f8469a1c (2026-09-02).
Data as JSON: /api/errors/1f35f81764009173.
Report an issue: GitHub.