Verifying JWT Signature using public key endpoint

前端 未结 1 476
醉梦人生
醉梦人生 2020-12-06 01:26

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

相关标签:
1条回答
  • 2020-12-06 02:10

    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()));
    
    0 讨论(0)
提交回复
热议问题