insights

Introduction to JSON Web Tokens

· John Doe

978 Views

What is JSON Web Token?

JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA or ECDSA.

JSON Web Tokens can be integrity protected with a hash-based message authentication code (HMAC). The producer and consumer must posses a shared secret, negotiated through some out-of-band mechanism before the JWS-protected object is communicated (unless the producer secures the JWS object for itself).

정보를 비밀리에 전달하거나 인증할 때 주로 사용하는 토큰으로, Json객체를 이용함.

그냥 DB에 인증 코드를 저장 하는 경우도 많지만 어디에도 저장하지 않는 방법도 흔히 쓰인다. 단순하게는 그냥 인증 정보를 HMAC 으로 사인하기만 하더라도 보안상 충분하고 더 많은 기능이 있는 JWT같은 방식을 사용할 수도 있다.

JWT는 Json Web Token의 약자로 일반적으로 클라이언트와 서버 사이에서 통신할 때 권한을 위해 사용하는 토큰이다. 웹 상에서 정보를 Json형태로 주고 받기 위해 표준규약에 따라 생성한 암호화된 토큰으로 복잡하고 읽을 수 없는 string 형태로 저장되어있다.

 

HMAC (Hash-Based Message Authentication Codes) Definition

Hash-based message authentication code (or HMAC) is a cryptographic authentication technique that uses a hash function and a secret key.

With HMAC, you can achieve authentication and verify that data is correct and authentic with shared secrets, as opposed to approaches that use signatures and asymmetric cryptography.

-메세지 인증을 위한 Keyed-Hasing의 약자
-인증할 데이터와 공유 비밀키에 대해 암호화 해시 함수(예. SHA1, SHA256)를 실행하여 얻은 메시지 인증코드

  • 전자 서명과 유사 : 무결성/진정성 강화, 암호키 사용, 해시 함수 사용
  • 전자 서명과 차이 : 전자 서명(비대칭키), HMAC(공개키)

-인증과정

  1. 해쉬 생성 : 클라이언트는 key + message를 HMAC 알고리즘으로 처리하여 hash 값을 만들어낸다.
  2. 요청 보내기 : 생성된 hash와 message를 HTTP 요청으로 REST API서버에게 보낸다. 보통 hash는 HTTP 헤더 또는 url에 포함된다.
  3. 해쉬 생성 : 서버는 클라이언트에게서 받은 요청 내의 message와 본인이 가지고있던 key를 조합하여 HMAC으로 hash값을 생성한다.
  4. 비교 : 클라이언트에서 넘어온 hash와 서버에서 생성된 hash가 동일한지 비교한다. 동일하면 인증 성공이다.

 

JWT: Choosing between HMAC and RSA

HMAC is used to prevent manipulation by someone who does not have access to the secret. Typically this means preventing manipulation by the client if the secret is only known to the server or to prevent manipulation in transit if the secret is known to client and server.

An RSA based signature is used to prevent manipulation and also to allow others to verify the integrity and source of the data without being able to manipulate the data. This can be done because the private key is only known to the provider and signer of the data while the public key is known to everybody who likes to verify the integrity.

What to choose thus depends on your specific use case. If the server just needs to protect the token against manipulation by the client then using HMAC with a server side secret is enough. If instead it needs to be also proven to others that the token was created by a specific (trusted) server then RSA based signatures should be used.

 

Learn about JSON Web Tokens, what are they, how they work, when and why you should use them.
It is my understanding that HMAC is a symmetric signing algorithm (single secret key) whereas RSA is an asymmetric signing algorithm (private/public key pair). I am trying to choose between these 2
Okta Looks like you have Javascript turned off! Please enable it to improve your browsing experience. Skip to main content Registration for Oktane is open! Registration for Oktane is open! Register now Register now Register now for Oktane +1 (800) 425-126
안녕하세요! HMAC 인증 이라는게 참 처음접하면 이게 어떤 원리로 동작하는건지 혼란스러운데, 찾아보니 영어로는 쉽게 잘 설명해주는 글들이 많은데 한국어로는 쉬운 설명이 정말 거의 없더라구요. 그래서 제가 하나 적어보기로 했습니다. HMAC을…
Mac이란?Message Authentication Code의 약자로 "인증된 메세지코드"라는 의미비즈니스 의사 결정과 프로세스는 정확하고 신뢰가능한 데이터에 의존적데이터 변조와 변경 사항이 눈에 띄지 않으면 의사 결정 밒 프로세스에 영향을 미칠 수 있음데이터를 인터넷
JWT(Json Web Token) > 정보를 비밀리에 전달하거나 인증할 때 주로 사용하는 토큰으로, Json객체를 이용함 JWT는 Json Web Token의 약자로 일반적으로 클라이언트와 서버 사이에서 통신할 때 권한을 위해 사용하는 토큰이다. 웹 상에서 정보를 Json형태로 주고 받기 위해 표준규약에 따라 생성한 암호화된 토큰으로 복잡하고 읽을 수 ...

JWT HMAC RSA