I read a number of blog posts and found that it is tough to keep the secret-key a secret and if using a symmetric algorithm for JWT creation, the generator has the power to create as well as validate the JWT. This seems a place where it may be misused.

This brings in picture RSA-based (asymmetric algorithm for JWT creation). These JWT seem to be a better choice if we want single authority for JWT creation.

When should one use HMAC-based JWT?

It would be so nice if you could give an example scenario.

1 Answer 1


You have a server which has a secret key. You want to give another party some type of claim (for example, you could give a user a token saying they're authenticated), so you sign it and hand the signed claim to that party. Then they can present that claim at a later time and you can verify:

  1. Authentication: that you signed it, assuming you didn't share your secret, and...

  2. Data Integrity: that the data has not been altered.

If you're sending a claim that another party needs to verify, then use an asymmetric digital signature algorithm, such as RSA. This is called Non-Repudiation and is not a property of HMACs.

Another example: You're sending another server some data that you expect that server to return to you at a later date, but you need to make sure that server didn't tamper with that data. You can sign it with an HMAC.

Ultimately this question is equivalent to: "What's the difference between MACs and DSAs?" and there is lots more reading under that topic.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .