SignatureException: JWT signature does not match locally computed signature #864
-
We generate keypair to sign the jwt token with private key and parse the claims using public key. Public key is being converted as string using following code and stored in cache to verify,
Using Keylocator it works fine sometime. But, the code throws SignatureException: JWT signature does not match locally computed signature randomly. This issues is completely random. Not sure what's the reason? Any limitation with the library? or any code issue from my side? Note: using jjwt 0.12.3 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
We haven't experienced any problems in JJWT before with random public key data working sometimes and not working during other times. Odds are very high that there's a problem with creating the RSAPublicKeySpec correctly and/or saving or parsing the String data correctly. For example, in most cryptographic contexts where a BigInteger is required, the data represents unsigned bytes, so we always use the Converting the BigInteger values to a numeric String, trimming and then back again could be problematic. In crypto contexts, the |
Beta Was this translation helpful? Give feedback.
-
@kalidasstamil Any update or reply to my post above? |
Beta Was this translation helpful? Give feedback.
We haven't experienced any problems in JJWT before with random public key data working sometimes and not working during other times. Odds are very high that there's a problem with creating the RSAPublicKeySpec correctly and/or saving or parsing the String data correctly.
For example, in most cryptographic contexts where a BigInteger is required, the data represents unsigned bytes, so we always use the
BigInteger(1, bytes)
constructor:jjwt/impl/src/main/java/io/jsonwebtoken/impl/lang/BigIntegerUBytesConverter.java
Line 53 in d4a0827
Converting the BigInteger values to a numeric String, trimming and then back again could be problematic. In…