3
I recently started to study the possibility of starting to use JSON Webtokens in my projects, given their advantages. From what I understand, there is a symmetrical form and an asymmetric way of generating the signature for the tokens. The symmetric seems to be the most common, which I have seen in several examples, signing from the same key stored somewhere in the system (correct me if I’m talking nonsense), as for example in this line using the package jsonwebtoken with Node.js Express:
var token = jwt.sign(user, app.get('superSecret'), {
expiresInMinutes: 1440
});
Note that all signatures are based on superSecret
, previously stored in the variable app
.
If this is the symmetrical method, what would the asymmetrical one look like? I don’t know much about cryptography, but I do know that when we talk about asymmetrical keys, there must be a pair of keys: a private and a public key.
How would this fit into the authentication process of a web application? Someone could explain to me and/or give an example of how JWT works with asymmetrical signature?
And yet, for that purpose (authentication in a web app), which of the two methods is safer?
Thank you very much for the answer. Very enlightening. I could exemplify cases where it would be better for me to use asymmetric rather than symmetric cryptography?
– Pedro Vinícius
I’ll add the answer.
– flpms