JWT Private / Public Key Confusion

With JWT, the possession and the use of the key materials are exactly the same as any other contexts where cypher operations occur.

For signing:

  • The private key is owned by the issuer and is used to compute the signature.
  • The public key can be shared with all parties that need to verify the signature.

For encryption:

  • The private key is owned by the recipient and is used to decrypt the data.
  • The public key can be shared to any party that want to send sensitive data to the recipient.

The encryption is rarely used with JWT. Most of the time the HTTPS layer is sufficient and the token itself only contain a few information that are not sensitive (datatime, IDs…).

The issuer of the token (the authentication server) has a private key to generate signed tokens (JWS). These tokens are sent to the clients (an API server, a web/native application…).
The clients can verify the token with the public key. The key is usually fetched using a public URI.

If you have sensitive data that shall not be disclosed to a third party (phone numbers, personnal address…), then the encrypted tokens (JWE) is highly recommended.
In this case, each client (i.e. recipient of a token) shall have a private key and the issuer of the token must encrypt the token using the public key of each recipient. This means that the issuer of the token can select the appropriate key for a given client.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)