php-jwt: "OpenSSL unable to verify data..."
I am unable to get passed this error when calling JWT::decode()
:
Uncaught exception 'DomainException' with message 'OpenSSL unable to verify data: error:0906D06C:PEM routines:PEM_read_bio:no start line
Error comes from this code piece:
$private_key = "-----BEGIN PRIVATE KEY-----\n[VERY_LONG_PRIVATE_KEY]\n-----END PRIVATE KEY-----\n";
$openssl_private_key = openssl_pkey_get_private($private_key);
$details = openssl_pkey_get_details($openssl_private_key);
$public_key = $details['key'];
$token = 'LONG_TOKEN_KEY';
return JWT::decode($token, $public_key, array('RS256'));
I have tried using both $private_key
and $public_key
as the second argument of decode()
. the $public_key
is the only one that gets me this far. $private_key
leaves me with:
openssl_verify(): supplied key param cannot be coerced into a public key...
After hours of googling, there doesn’t seem to be anyone else that have this problem. Let alone experience it. How can I solve this?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 18
You must use private key for encode and public key for decode. The keys you can generate on command line like this:
Here is an example from start page with RS256
Here is an example with private key only:
openssl_pkey_get_private
works also as replacement foropenssl_get_privatekey
.This is the output from example:
Testet on PHP Version 5.3.17 and 5.5.14 (edit: same key from example above) (edit 2: Signature is SHA1, not SHA256. Signature will nor Verified on jwt.io, see some days later.)