I\'m wanting to verify the signature of some JWTs from Microsoft. I\'m using Spring-Boot, the JJWT library and following endpoint: https://login.microsoftonline.com/common/d
x5c
contains the certification chain. The first certificate of the chain must match with the key value represented by the other values in the JWK, in this case n
and e
, therefore the public key extracted from x5c[0]
and the one built with n
and e
must be exactly the same
JWK values are encoded in base64url, not in base64. Change
BigInteger modulus = new BigInteger(1, Base64.decodeBase64(jsonKey.getN()));
BigInteger exponent = new BigInteger(1, Base64.decodeBase64(jsonKey.getE()));
with
BigInteger modulus = new BigInteger(1, Base64.getUrlDecoder().decode(jsonKey.getN()));
BigInteger exponent = new BigInteger(1, Base64.getUrlDecoder().decode(jsonKey.getE()));