During unit testing I noticed some expected behavior regarding the.
I used your code to generate a RsaJsonWebKey keypair. Once created I set the algorithm to RS512. I created a public JWK based off of that. At that point, the keypair and the JWK had the same key-id, algorithm and signature. Next in the UT, I altered the algorithm of the JWK to RS256. I expected this to fail but it still matches and validates. Granted, the key-id and most importantly, the signatures still matched. Is algorithm really necessary? Looking into the Jose4J source code, it appears it's never set to match against the JWK.
in method SimpleJwkFilter.filter()
match &= isMatch(alg, jwk.getAlgorithm()); <-- alg is never set and therefore passes isMatch