Write public RSA key to disk

I think it's useful even though we don't read it.
master
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> { class RsaKeyProvider : Provider<RSAPrivateCrtKeyParameters> {
override fun get(): RSAPrivateCrtKeyParameters { override fun get(): RSAPrivateCrtKeyParameters {
return if (Files.exists(PATH)) { return if (Files.exists(PRIVATE_PATH)) {
Rsa.readPrivateKey(PATH) Rsa.readPrivateKey(PRIVATE_PATH)
} else { } else {
val (_, private) = Rsa.generateKeyPair() val (public, private) = Rsa.generateKeyPair()
Rsa.writePrivateKey(PATH, private) Rsa.writePublicKey(PUBLIC_PATH, public)
Rsa.writePrivateKey(PRIVATE_PATH, private)
private private
} }
} }
companion object { 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 /private.key
/public.key

Loading…
Cancel
Save