From 9fe6333aebdb5e42ae4bcd4cf8adb008dc1b3c3c Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Fri, 8 Mar 2024 17:53:49 +0800 Subject: [PATCH] Fix: JwtUtil - fix general key bug --- src/main/kotlin/top/fatweb/oxygen/api/OxygenApiApplication.kt | 2 +- src/main/kotlin/top/fatweb/oxygen/api/util/JwtUtil.kt | 2 +- src/main/resources/application-config-template.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/top/fatweb/oxygen/api/OxygenApiApplication.kt b/src/main/kotlin/top/fatweb/oxygen/api/OxygenApiApplication.kt index 146c2fb..6bfaadb 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/OxygenApiApplication.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/OxygenApiApplication.kt @@ -59,7 +59,7 @@ fun main(args: Array) { OxygenApiApplication::class.java.getResource("/application-config-template.yml")?.readText()?.let { File("data/application-config.example.yml").writeText( it.replace( - "\$uuid\$", UUID.randomUUID().toString().replace("-", "") + "\$uuid\$", UUID.randomUUID().toString() ) ) } diff --git a/src/main/kotlin/top/fatweb/oxygen/api/util/JwtUtil.kt b/src/main/kotlin/top/fatweb/oxygen/api/util/JwtUtil.kt index a831d5f..8622a6b 100644 --- a/src/main/kotlin/top/fatweb/oxygen/api/util/JwtUtil.kt +++ b/src/main/kotlin/top/fatweb/oxygen/api/util/JwtUtil.kt @@ -25,7 +25,7 @@ object JwtUtil { * @since 1.0.0 */ private fun generalKey(): SecretKeySpec { - val encodeKey = Base64.getDecoder().decode(SecurityProperties.jwtKey) + val encodeKey = Base64.getEncoder().encode(SecurityProperties.jwtKey.toByteArray()) return SecretKeySpec(encodeKey, 0, encodeKey.size, "AES") } diff --git a/src/main/resources/application-config-template.yml b/src/main/resources/application-config-template.yml index dbe25d5..6747dbc 100644 --- a/src/main/resources/application-config-template.yml +++ b/src/main/resources/application-config-template.yml @@ -11,7 +11,7 @@ app: # token-prefix: "Bearer " # Token prefix # jwt-ttl: 2 # The life of token # jwt-ttl-unit: hours # Unit of life of token [nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days] - jwt-key: $uuid$ # Key to generate token (Only numbers and letters allow) + jwt-key: $uuid$ # Key to generate token # jwt-issuer: Oxygen # Token issuer # redis-ttl: 20 # The life of token in redis # redis-ttl-unit: minutes # Unit of life of token in redis [nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days]