File tree 2 files changed +15
-7
lines changed
src/main/kotlin/scul/projectscul/global/security/jwt
2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 1
1
package scul.projectscul.global.security.jwt
2
2
3
+ import io.jsonwebtoken.SignatureAlgorithm
4
+ import io.jsonwebtoken.security.Keys
3
5
import org.springframework.beans.factory.annotation.Value
4
6
import org.springframework.stereotype.Component
7
+ import java.security.Key
8
+ import java.util.*
9
+ import javax.crypto.SecretKey
5
10
6
11
@Component
7
12
data class JwtProperties (
@@ -10,4 +15,9 @@ data class JwtProperties(
10
15
@Value(" \$ {jwt.secret-key}" ) val secretKey : String ,
11
16
@Value(" \$ {jwt.access-exp}" ) val accessExp : Long ,
12
17
@Value(" \$ {jwt.refresh-exp}" ) val refreshExp : Long
13
- )
18
+ ){
19
+ val secretKey2: SecretKey = Keys .hmacShaKeyFor(
20
+ Base64 .getEncoder().encodeToString(secretKey.toByteArray())
21
+ .toByteArray(Charsets .UTF_8 )
22
+ )
23
+ }
Original file line number Diff line number Diff line change @@ -23,9 +23,7 @@ class JwtTokenProvider(
23
23
private val authDetailsService : AuthDetailsService ,
24
24
private val refreshTokenRepository : RefreshTokenRepository
25
25
) {
26
-
27
- val key: Key = Keys .secretKeyFor(SignatureAlgorithm .HS256 )
28
-
26
+
29
27
companion object {
30
28
private const val ACCESS = " access_token"
31
29
private const val REFRESH = " refresh_token"
@@ -45,7 +43,7 @@ class JwtTokenProvider(
45
43
return Jwts .builder()
46
44
.setSubject(accountId)
47
45
.claim(" typ" , typ)
48
- .signWith(key , SignatureAlgorithm .HS256 )
46
+ .signWith(jwtProperties.secretKey2 , SignatureAlgorithm .HS256 )
49
47
.setExpiration(Date (System .currentTimeMillis() + exp * 1000 ))
50
48
.setIssuedAt(Date ())
51
49
.compact()
@@ -57,7 +55,7 @@ class JwtTokenProvider(
57
55
.setHeaderParam(" type" , type)
58
56
.setIssuedAt(Date ())
59
57
.setExpiration(Date (System .currentTimeMillis() + ttl * 1000 ))
60
- .signWith(key , SignatureAlgorithm .HS256 )
58
+ .signWith(jwtProperties.secretKey2 , SignatureAlgorithm .HS256 )
61
59
.compact()
62
60
}
63
61
@@ -74,7 +72,7 @@ class JwtTokenProvider(
74
72
private fun getClaims (token : String ): Claims {
75
73
return try {
76
74
Jwts .parser()
77
- .setSigningKey(key )
75
+ .setSigningKey(jwtProperties.secretKey2 )
78
76
.parseClaimsJws(token)
79
77
.body
80
78
} catch (e: ExpiredJwtException ) {
You can’t perform that action at this time.
0 commit comments