mirror of https://github.com/usbharu/Hideout.git
fix: 鍵の読み込み方法を修正
This commit is contained in:
parent
56b75b9655
commit
a5188bbb65
|
@ -144,10 +144,11 @@ class KtorKeyMap(private val userAuthRepository: IUserAuthService) : KeyMap {
|
||||||
override fun getPublicKey(keyId: String?): PublicKey = runBlocking {
|
override fun getPublicKey(keyId: String?): PublicKey = runBlocking {
|
||||||
val username = (keyId ?: throw IllegalArgumentException("keyId is null")).substringBeforeLast("/pubkey")
|
val username = (keyId ?: throw IllegalArgumentException("keyId is null")).substringBeforeLast("/pubkey")
|
||||||
.substringAfterLast("/")
|
.substringAfterLast("/")
|
||||||
val publicBytes = java.util.Base64.getDecoder().decode(
|
val publicBytes = Base64.getDecoder().decode(
|
||||||
userAuthRepository.findByUsername(
|
userAuthRepository.findByUsername(
|
||||||
username
|
username
|
||||||
).publicKey
|
).publicKey?.replace("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----")?.replace("", "")
|
||||||
|
?.replace("\\n", "")
|
||||||
)
|
)
|
||||||
val x509EncodedKeySpec = X509EncodedKeySpec(publicBytes)
|
val x509EncodedKeySpec = X509EncodedKeySpec(publicBytes)
|
||||||
return@runBlocking KeyFactory.getInstance("RSA").generatePublic(x509EncodedKeySpec)
|
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 {
|
override fun getPrivateKey(keyId: String?): PrivateKey = runBlocking {
|
||||||
val username = (keyId ?: throw IllegalArgumentException("keyId is null")).substringBeforeLast("/pubkey")
|
val username = (keyId ?: throw IllegalArgumentException("keyId is null")).substringBeforeLast("/pubkey")
|
||||||
.substringAfterLast("/")
|
.substringAfterLast("/")
|
||||||
val publicBytes = java.util.Base64.getDecoder().decode(
|
val publicBytes = Base64.getDecoder().decode(
|
||||||
userAuthRepository.findByUsername(
|
userAuthRepository.findByUsername(
|
||||||
username
|
username
|
||||||
).privateKey
|
).privateKey?.replace("-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----")?.replace("", "")
|
||||||
|
?.replace("\\n", "")
|
||||||
)
|
)
|
||||||
val x509EncodedKeySpec = X509EncodedKeySpec(publicBytes)
|
val x509EncodedKeySpec = X509EncodedKeySpec(publicBytes)
|
||||||
return@runBlocking KeyFactory.getInstance("RSA").generatePrivate(x509EncodedKeySpec)
|
return@runBlocking KeyFactory.getInstance("RSA").generatePrivate(x509EncodedKeySpec)
|
||||||
|
|
Loading…
Reference in New Issue