fix: 鍵を強固に、PEMを修正

This commit is contained in:
usbharu 2023-04-29 16:47:58 +09:00
parent 099428ef00
commit 4a689901d9
1 changed files with 3 additions and 3 deletions

View File

@ -31,7 +31,7 @@ class UserAuthService(
override suspend fun generateKeyPair(): KeyPair { override suspend fun generateKeyPair(): KeyPair {
val keyPairGenerator = KeyPairGenerator.getInstance("RSA") val keyPairGenerator = KeyPairGenerator.getInstance("RSA")
keyPairGenerator.initialize(1024) keyPairGenerator.initialize(2048)
return keyPairGenerator.generateKeyPair() return keyPairGenerator.generateKeyPair()
} }
@ -44,11 +44,11 @@ class UserAuthService(
fun PublicKey.toPem(): String { fun PublicKey.toPem(): String {
return "-----BEGIN PUBLIC KEY-----\n" + return "-----BEGIN PUBLIC KEY-----\n" +
Base64.getEncoder().encodeToString(encoded).chunked(64).joinToString("\n") + Base64.getEncoder().encodeToString(encoded).chunked(64).joinToString("\n") +
"\n-----END PUBLIC KEY-----" "\n-----END PUBLIC KEY-----\n"
} }
fun PrivateKey.toPem(): String { fun PrivateKey.toPem(): String {
return "-----BEGIN PRIVATE KEY-----\n" + return "-----BEGIN PRIVATE KEY-----\n" +
Base64.getEncoder().encodeToString(encoded).chunked(64).joinToString("\n") + Base64.getEncoder().encodeToString(encoded).chunked(64).joinToString("\n") +
"\n-----END PRIVATE KEY-----" "\n-----END PRIVATE KEY-----\n"
} }