fix: 鍵の形式を修正2

This commit is contained in:
usbharu 2023-03-31 17:48:42 +09:00
parent bc4807ddc9
commit aaedafff95
2 changed files with 5 additions and 5 deletions

View File

@ -164,7 +164,7 @@ class KtorKeyMap(private val userAuthRepository: IUserAuthService) : KeyMap {
val publicBytes = Base64.getDecoder().decode(
userAuthRepository.findByUsername(
username
).privateKey?.replace("-----BEGIN RSA PRIVATE KEY-----", "")?.replace("-----END RSA PRIVATE KEY-----", "")
).privateKey?.replace("-----BEGIN PRIVATE KEY-----", "")?.replace("-----END PRIVATE KEY-----", "")
?.replace("\n", "")
)
val x509EncodedKeySpec = PKCS8EncodedKeySpec(publicBytes)

View File

@ -91,13 +91,13 @@ class UserAuthService(
}
public fun PublicKey.toPem(): String {
return "-----BEGIN RSA PUBLIC KEY-----" +
return "-----BEGIN PUBLIC KEY-----" +
Base64.getEncoder().encodeToString(encoded).chunked(64).joinToString("\n") +
"-----END RSA PUBLIC KEY-----"
"-----END PUBLIC KEY-----"
}
public fun PrivateKey.toPem(): String {
return "-----BEGIN RSA PRIVATE KEY-----" +
return "-----BEGIN PRIVATE KEY-----" +
Base64.getEncoder().encodeToString(encoded).chunked(64).joinToString("\n") +
"-----END RSA PRIVATE KEY-----"
"-----END PRIVATE KEY-----"
}