Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
785 B
24 lines
785 B
package dev.openrs2.crypto
|
|
|
|
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters
|
|
import java.nio.file.Files
|
|
import java.nio.file.Paths
|
|
import javax.inject.Provider
|
|
|
|
class RsaKeyProvider : Provider<RSAPrivateCrtKeyParameters> {
|
|
override fun get(): RSAPrivateCrtKeyParameters {
|
|
return if (Files.exists(PRIVATE_PATH)) {
|
|
Rsa.readPrivateKey(PRIVATE_PATH)
|
|
} else {
|
|
val (public, private) = Rsa.generateKeyPair(Rsa.CLIENT_KEY_LENGTH)
|
|
Rsa.writePublicKey(PUBLIC_PATH, public)
|
|
Rsa.writePrivateKey(PRIVATE_PATH, private)
|
|
private
|
|
}
|
|
}
|
|
|
|
companion object {
|
|
private val PUBLIC_PATH = Paths.get("conf/public.key")
|
|
private val PRIVATE_PATH = Paths.get("conf/private.key")
|
|
}
|
|
}
|
|
|