Tutorial: Create and Verify JWTs in Java

Tutorial: Create and Verify JWTs in Java

This article explores the benefits of token authentication with JWTs for Java apps.

Krishna Gavade

Hi, Great post, I am seeking help for RSA auth, can you please provide an example JWT token decode for RSA key signature validation using public key .pub file or public key from .txt file

tom johnes


This tutorial seems to be deprecated or I fear it is not totally accurate. I’m currently using version 0.9.1 of JWT available here https://mvnrepository.com/a…

- First of all, when decoding, the parser returns Jws<claims> instead of Claims (as mentioned above)
- Finally, the values date claims (exp, iat, etc…) get trmmed 3 charaters when it’s printed in Java console with the getBody() method. Something is wrong with the interaction between getBody() and System.out.println

Any idea ho to solve the second problem listed above ?

Nagendra Sai

Thanks Andrew

Cyril Franceschini

How do you verify the token before reading it?


try using shorter secret key


I just tried the code for creating a JWT, and got the following exception:

java.lang.NoSuchFieldError: id_alg_AEADChaCha20Poly1305

Any ideas as to how to resolve this error ?


Looks like this line of code is problematic, for some reason:

SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.RS256;

Olivier M.

Don’t use JJWT if you need performances. Parsing claims is really slow.