Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit 6476063

Browse files
author
kahverengi
committed
Add random key for token to be more safer
1 parent 7a25c78 commit 6476063

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/kotlin/com/parnote/util/TokenUtil.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ package com.parnote.util
33
import com.parnote.db.DatabaseManager
44
import com.parnote.db.model.Token
55
import io.jsonwebtoken.Jwts
6+
import io.jsonwebtoken.SignatureAlgorithm
7+
import io.jsonwebtoken.io.Encoders
68
import io.jsonwebtoken.security.Keys
79
import io.vertx.core.AsyncResult
810
import io.vertx.ext.sql.SQLConnection
911
import java.util.*
1012

13+
1114
object TokenUtil {
1215
enum class SUBJECT {
1316
LOGIN_SESSION,
@@ -32,8 +35,11 @@ object TokenUtil {
3235
return@getSecretKeyByID
3336
}
3437

38+
val key = Keys.secretKeyFor(SignatureAlgorithm.HS256)
39+
3540
val token = Jwts.builder()
3641
.setSubject(subject.toString())
42+
.setHeaderParam("key", Encoders.BASE64.encode(key.encoded))
3743
.signWith(
3844
Keys.hmacShaKeyFor(
3945
Base64.getDecoder().decode(

0 commit comments

Comments
 (0)