1. Create Token
String secretKey = "키값";
String clientId = "";
String apiKey = "";
public String createToken(){
//1. 유효기간
int Validity = 1000 * 60 * 60 * 24 * 1;//1day
//2. 암호화
SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
//3. 발급시간, 만료시간
Date createdTime = new Date();
Date expireTime = new Date(createdTime.getTime() + Validity);
//4. 서명데이터
byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(secretKey);
Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName());
//5. 헤더데이터
Map<String, Object> headerMap = new HashMap<String, Object>();
headerMap.put("typ", "JWT");
headerMap.put("alg", "HS256");
Map<String, Object> claimMap = new HashMap<String, Object>();
claimMap.put("clientId", clientId);
claimMap.put("apiKey", apiKey);
//6. build token
JwtBuilder builder = Jwts.builder().setHeader(headerMap);
.addClaims(claimMap)
.setIssuer(clientId)
.setExpiration(expireTime)
.setIssuedAt(createdTime)
.signWith(SignatureAlgorithm, signingKey);
return builder.compact();
}'REST API' 카테고리의 다른 글
| REST API Controller : 전자정부 Controller (0) | 2026.05.22 |
|---|---|
| HTTPS REST API POST : 전자정부 DAO (0) | 2026.05.22 |
| HTTPS REST API POST : 전자정부 Service (0) | 2026.05.22 |
| HTTPS REST API POST : 전자정부 ServiceImpl (0) | 2026.05.22 |