안녕하세요, 오늘은 JWT 에 대해 정리해 보았습니다.
JWT란 무엇인가?
JWT는 JSON 형식으로 정보를 안전하게 전송하기 위한 방법입니다. 주로 사용자 인증을 위해 사용되며, 클라이언트와 서버 간의 신뢰할 수 있는 정보 교환을 가능하게 합니다. JWT는 세 부분으로 나뉘어져 있으며, 각 부분은 점(.)으로 구분됩니다.
JWT의 구조
JWT는 크게 세 가지 부분으로 구성됩니다: Header, Payload, Signature입니다.
아래 이미지는 JWT의 구조를 잘 보여줍니다.

JWT의 사용 사례
JWT는 다양한 상황에서 사용될 수 있습니다. 예를 들어:
JWT 생성 및 검증 방법
JWT를 생성하는 과정은 다음과 같습니다:
이 과정을 통해 생성된 JWT는 클라이언트에 전달됩니다. 클라이언트는 이후 요청 시 이 JWT를 서버에 전송하여 인증을 받습니다.
JWT의 장점과 단점
JWT의 장점은 다음과 같습니다
하지만 단점도 존재합니다
오늘의 코드카타
class Solution {
public int solution(String dartResult) {
int answer = 0;
int[] dart = new int[3];
int n = 0, idx = 0;
String numstr = "";
for (int i = 0; i < dartResult.length(); i++) {
char c = dartResult.charAt(i);
if (c >= '0' && c <= '9') {
numstr += String.valueOf(c);
}
else if (c == 'S' || c == 'D' || c == 'T') {
n = Integer.parseInt(numstr);
if (c == 'S') {
dart[idx++] = (int) Math.pow(n, 1);
} else if (c == 'D') {
dart[idx++] = (int) Math.pow(n, 2);
} else {
dart[idx++] = (int) Math.pow(n, 3);
}
numstr = "";
}
else {
if (c == '*') {
dart[idx - 1] *= 2;
if (idx - 2 >= 0) {
dart[idx - 2] *= 2;
}
} else {
dart[idx - 1] *= (-1);
}
}
}
answer = dart[0] + dart[1] + dart[2];
return answer;
}
}
public class Main {
public static void main(String[] args) {
Solution solution = new Solution();
System.out.println(solution.solution("1S2D*3T"));
System.out.println(solution.solution("1D2S#10S"));
System.out.println(solution.solution("1D2S0T"));
System.out.println(solution.solution("1S*2T*3S"));
System.out.println(solution.solution("1D#2S*3S"));
System.out.println(solution.solution("1T2D3D#"));
System.out.println(solution.solution("1D2S3T*"));
}
}
[1차] 다트게임