firebase / php-jwt

PHP package for JWT
BSD 3-Clause "New" or "Revised" License
9.38k stars 1.27k forks source link

OpenSSL RS256 Error #509

Closed UUSR closed 1 year ago

UUSR commented 1 year ago

When I try to get the token I get the following error: Warning: openssl_sign(): supplied key param cannot be coerced into a private key Fatal error: Uncaught DomainException: OpenSSL unable to sign data

In file JWT.php (Line 235) case 'openssl': $signature = ''; $success = \openssl_sign($msg, $signature, $key, $algorithm); // @phpstan-ignore-line if (!$success) { throw new DomainException('OpenSSL unable to sign data');

When I am trying to validate the token I get, the error below: Warning: openssl_verify(): supplied key param cannot be coerced into a public key "OpenSSL error: error:0909006C:PEM routines:get_name:no start line"

In file JWT.php (Line 292) case 'openssl': $success = \openssl_verify($msg, $signature, $keyMaterial, $algorithm); // @phpstan-ignore-line if ($success === 1) { return true; } if ($success === 0) { return false; }

I'm using Firebase on my Apache Server, any suggestions.

bshaffer commented 1 year ago

This seems like the string you are providing as the public key is not the correct format. The error states that the key param cannot be coerced into a public key, meaning it's improperly formatted. It then goes on to say that there's "no start line".

So, it seems like there's something wrong with the keys you're using.