I am having trouble verifying an RS256 signature in PHP from a JWT.
I have
$to_verify = substr(Cookie::get('CF_Authorization'), 0, strrpos(Cookie::get('CF_Authorization'), "."));
$signature = base64_decode(explode('.', Cookie::get('CF_Authorization'))[2]);
return openssl_verify($to_verify, $signature, $cert, 'RSA-SHA256'));
Part of my problem is I don't know what is the most correct algorithm to use the header says "alg": "RS256". So is that:
- OPENSSL_ALGO_SHA256
- "SHA256"
- "sha256"
- "RSA-SHA256"
- "sha256WithRSAEncryption"
- Something else?
I've tried all of those from the php docs that sounds like they could be right, but not matter what I try it always returns 0 (not verified) but according to jwt.io the jwt, signature, and public key I am testing with is valid.
I'm not sure what I am doing wrong.
I was able to find some close-ish implementations after much more searching and figured it out.
First, the algorithm needed to be set to "SHA256".
Second, Instead of base64_decode I needed to so a slightly modified decoding, which I found a function for in an open source implementation
These two together, and now it works.