translation

This is an AI translated post.

Seize the day

What is JWT (JSON Web Token)?

Select Language

  • English
  • 汉语
  • Español
  • Bahasa Indonesia
  • Português
  • Русский
  • 日本語
  • 한국어
  • Deutsch
  • Français
  • Italiano
  • Türkçe
  • Tiếng Việt
  • ไทย
  • Polski
  • Nederlands
  • हिन्दी
  • Magyar

Summarized by durumis AI

  • JSON Web Token (JWT) is an encrypted token that securely transmits information.
  • JWT consists of a header, payload, and signature, and the signature guarantees the integrity of the data.
  • JWT does not require separate management of state information, making it highly scalable in distributed environments.

What is JWT?

JSON Web Token (JWT) is a standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. It literally encrypts the necessary information into a token and uses it.


JWT is emphasized as a signed token. When signing with a public/private key pair, this signature ensures that only the party holding the private key signed the token. In other words, the server holding the key can tell if the token is valid.


JWT Structure

JWT consists of Header, Payload, and Signature.

Each part is Base64 encoded and separated by a dot (.). 

Header

{
    "alg": "HS256",
    "typ": "JWT"

The header contains two key pieces of information: the type of token (typ) and the signing algorithm used (alg). The signing algorithm is used to generate and verify the signature.

The typ is set to "JWT", and alg is written as HMAC, SHA256, etc. As in the example above, it means using the HS256 algorithm with the private key. 

Payload

{
    "sub": "1234567890",
    "name": "John Doe",
    "iat": 1516239022


The payload contains the Claims that you want to transmit in the token. Store user identification information or properties about the token in a key-value format. In other words, you can put anything you want!

The standard specification defines the key names in a compact form with three letters.

Registered claims are as follows. 

  • iss (Issuer): Token issuer (includes the issuer's unique identification information)
  • sub (Subject): The subject of the token
  • aud (Audience): Token recipient
  • exp (Expiration Time): Token expiration time (no longer valid after this time)
  • nbf (Not Before): Token activation date (the token cannot be used before this time)
  • iat (Issued At): Token issuance time
  • jti (JWT Id): JWT token identifier (used to distinguish between multiple issuers)


You can add and use additional values if there are any other necessary values. 

However, the payload is not an encrypted signed value, so it does not contain sensitive information.

Anyone can read it by decoding it. jwt.io You can also check it directly on the site.

Signature

HMACSHA256(
    base64UrlEncode(header) + "." +
    base64UrlEncode(payload),
    your-256-bit-secret

The header and payload are concatenated with a dot (.) after being Base64 encoded, and the server signs it using the private key, your-256-bit-secret. 

Therefore, only the server that issued the token can decrypt the signature using the private key.

To decrypt it, you can decrypt the signature with the private key, and then check if the base64UrlEncode(header) matches the JWT's header value and if the base64UrlEncode(payload) matches. 

The header and payload excluding the signature are only encoded, so you can see the information in the body, but the signature ensures the integrity and security of the information. 



JWT is Self-contained, containing all the necessary information, and it was created to overcome the disadvantages of stateful sessions, so a separate storage is not essential. 

There is no need to maintain sessions on the server side, making it stateless, which increases scalability in distributed systems or microservice architectures. 

It is protected by a signature, a digital signature, and can guarantee data integrity.

nofunfromdev
Seize the day
Seize the day
nofunfromdev
Use a free financial certificate instead of a paid common certificate! We introduce a financial certificate that can be issued for free instead of a common certificate. It is convenient because it can be issued in 3 minutes and used for 3 years. It can be applied for on the bank's website and can be used at Hometax, National
길리
길리
길리
길리
길리

April 17, 2024

Coocon Provides APIs for Implementing Non-face-to-face Customer Authentication Processes Coocon provides a variety of APIs, including identity card face matching verification, simple certificate, account holder inquiry, and 1 won account authentication, to simplify non-face-to-face customer authentication procedures and support the constructi
스타트업 커뮤니티 씬디스 (SeenThis.kr)
스타트업 커뮤니티 씬디스 (SeenThis.kr)
스타트업 커뮤니티 씬디스 (SeenThis.kr)
스타트업 커뮤니티 씬디스 (SeenThis.kr)

May 9, 2024

Introducing SECURET: A Web 3.0 Secure Messenger SECURET is a Web 3.0 secure messenger that allows anonymous use without registration. It emphasizes privacy and anonymity, and prevents hacking by using a one-time connection method through a QR code.
Hey, Duckky!
Hey, Duckky!
Hey, Duckky!
Hey, Duckky!
Hey, Duckky!

June 21, 2024

[Spring] What are Filter, Interceptor, and Argument Resolver? Learn in detail about the concepts and differences between Filter, Interceptor, and Argument Resolver that handle requests in Spring web applications. This article provides a comparative analysis of the implementation methods, timing of use, advantages an
제이온
제이온
제이온
제이온
제이온

April 27, 2024

We value your privacy durumis uses a passwordless method that does not store user passwords and uses email verification for login, strengthening privacy security. It is planned to be upgraded to a more secure passkey method in the future.
durumis official blog
durumis official blog
durumis logo
durumis official blog
durumis official blog

February 7, 2024

[Effective Java] Item 1: Consider Static Factory Methods Instead of Constructors Static factory methods provide a flexible and efficient way to create instances instead of constructors. They can have names, return instances that meet specific conditions, and improve performance through caching. Unlike the singleton pattern, they can c
제이온
제이온
제이온
제이온

April 27, 2024