Cannot create signature for JWT for APNs

I am trying to generate the signature for a JWT using a .p8 private key from Apple for APNs in PHP.

If I try to use the following command hash_hmac('sha256', $header . '.' . $payload, $key), when checking it in Apple's JSON Web Token Validator, I get that the signature is invalid.

I have also tried converting the .p8 private key to a PEM file and importing it into the OpenSSL library, but I am still getting the error message openssl_sign(): Supplied key param cannot be coerced into a private key.

But I generate the JWT using Apple's JSON Web Token Generator, everything goes well, even the request to APNs.

Thank you in advance!

Can't help with your PHP code, but https://jwt.io/libraries has example source code to create JWTs for many language and systems you might wish to use.

Cannot create signature for JWT for APNs
 
 
Q