Write public RSA key to disk

I think it's useful even though we don't read it.
bzip2
Graham 5 years ago
parent d9762d65bc
commit b8af6c0c90
  1. 12
      common/src/main/java/dev/openrs2/common/crypto/RsaKeyProvider.kt
  2. 1
      conf/.gitignore

@ -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")
}
}

1
conf/.gitignore vendored

@ -1 +1,2 @@
/private.key
/public.key

Loading…
Cancel
Save