fix: 鍵の読み込み方法を修正

This commit is contained in:
usbharu 2023-03-31 13:12:26 +09:00
parent 56b75b9655
commit a5188bbb65
1 changed files with 6 additions and 4 deletions

View File

@ -144,10 +144,11 @@ class KtorKeyMap(private val userAuthRepository: IUserAuthService) : KeyMap {
override fun getPublicKey(keyId: String?): PublicKey = runBlocking {
val username = (keyId ?: throw IllegalArgumentException("keyId is null")).substringBeforeLast("/pubkey")
.substringAfterLast("/")
val publicBytes = java.util.Base64.getDecoder().decode(
val publicBytes = Base64.getDecoder().decode(
userAuthRepository.findByUsername(
username
).publicKey
).publicKey?.replace("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----")?.replace("", "")
?.replace("\\n", "")
)
val x509EncodedKeySpec = X509EncodedKeySpec(publicBytes)
return@runBlocking KeyFactory.getInstance("RSA").generatePublic(x509EncodedKeySpec)
@ -156,10 +157,11 @@ class KtorKeyMap(private val userAuthRepository: IUserAuthService) : KeyMap {
override fun getPrivateKey(keyId: String?): PrivateKey = runBlocking {
val username = (keyId ?: throw IllegalArgumentException("keyId is null")).substringBeforeLast("/pubkey")
.substringAfterLast("/")
val publicBytes = java.util.Base64.getDecoder().decode(
val publicBytes = Base64.getDecoder().decode(
userAuthRepository.findByUsername(
username
).privateKey
).privateKey?.replace("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----")?.replace("", "")
?.replace("\\n", "")
)
val x509EncodedKeySpec = X509EncodedKeySpec(publicBytes)
return@runBlocking KeyFactory.getInstance("RSA").generatePrivate(x509EncodedKeySpec)