Skip to content

Commit 075085b

Browse files
committed
🦷 :: secret key 수정
1 parent 1b5324a commit 075085b

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package scul.projectscul.global.security.jwt
22

3+
import io.jsonwebtoken.SignatureAlgorithm
4+
import io.jsonwebtoken.security.Keys
35
import org.springframework.beans.factory.annotation.Value
46
import org.springframework.stereotype.Component
7+
import java.security.Key
8+
import java.util.*
9+
import javax.crypto.SecretKey
510

611
@Component
712
data class JwtProperties(
@@ -10,4 +15,9 @@ data class JwtProperties(
1015
@Value("\${jwt.secret-key}") val secretKey: String,
1116
@Value("\${jwt.access-exp}") val accessExp: Long,
1217
@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+
}

src/main/kotlin/scul/projectscul/global/security/jwt/JwtTokenProvider.kt

+4-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ class JwtTokenProvider(
2323
private val authDetailsService: AuthDetailsService,
2424
private val refreshTokenRepository: RefreshTokenRepository
2525
) {
26-
27-
val key: Key = Keys.secretKeyFor(SignatureAlgorithm.HS256)
28-
26+
2927
companion object {
3028
private const val ACCESS = "access_token"
3129
private const val REFRESH = "refresh_token"
@@ -45,7 +43,7 @@ class JwtTokenProvider(
4543
return Jwts.builder()
4644
.setSubject(accountId)
4745
.claim("typ", typ)
48-
.signWith(key, SignatureAlgorithm.HS256)
46+
.signWith(jwtProperties.secretKey2, SignatureAlgorithm.HS256)
4947
.setExpiration(Date(System.currentTimeMillis() + exp * 1000))
5048
.setIssuedAt(Date())
5149
.compact()
@@ -57,7 +55,7 @@ class JwtTokenProvider(
5755
.setHeaderParam("type", type)
5856
.setIssuedAt(Date())
5957
.setExpiration(Date(System.currentTimeMillis() + ttl * 1000))
60-
.signWith(key, SignatureAlgorithm.HS256)
58+
.signWith(jwtProperties.secretKey2, SignatureAlgorithm.HS256)
6159
.compact()
6260
}
6361

@@ -74,7 +72,7 @@ class JwtTokenProvider(
7472
private fun getClaims(token: String): Claims {
7573
return try {
7674
Jwts.parser()
77-
.setSigningKey(key)
75+
.setSigningKey(jwtProperties.secretKey2)
7876
.parseClaimsJws(token)
7977
.body
8078
} catch (e: ExpiredJwtException) {

0 commit comments

Comments
 (0)