|
|
|
@ -7,16 +7,18 @@ import javax.inject.Provider |
|
|
|
|
|
|
|
|
|
class RsaKeyProvider : Provider<RSAPrivateCrtKeyParameters> { |
|
|
|
|
override fun get(): RSAPrivateCrtKeyParameters { |
|
|
|
|
return if (Files.exists(PATH)) { |
|
|
|
|
Rsa.readPrivateKey(PATH) |
|
|
|
|
return if (Files.exists(PRIVATE_PATH)) { |
|
|
|
|
Rsa.readPrivateKey(PRIVATE_PATH) |
|
|
|
|
} else { |
|
|
|
|
val (_, private) = Rsa.generateKeyPair() |
|
|
|
|
Rsa.writePrivateKey(PATH, private) |
|
|
|
|
val (public, private) = Rsa.generateKeyPair() |
|
|
|
|
Rsa.writePublicKey(PUBLIC_PATH, public) |
|
|
|
|
Rsa.writePrivateKey(PRIVATE_PATH, private) |
|
|
|
|
private |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
private val PATH = Paths.get("conf/private.key") |
|
|
|
|
private val PUBLIC_PATH = Paths.get("conf/public.key") |
|
|
|
|
private val PRIVATE_PATH = Paths.get("conf/private.key") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|