forked from openrs2/openrs2
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.
22 lines
619 B
22 lines
619 B
package dev.openrs2.common.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(PATH)) {
|
|
Rsa.readPrivateKey(PATH)
|
|
} else {
|
|
val (_, private) = Rsa.generateKeyPair()
|
|
Rsa.writePrivateKey(PATH, private)
|
|
private
|
|
}
|
|
}
|
|
|
|
companion object {
|
|
private val PATH = Paths.get("conf/private.key")
|
|
}
|
|
}
|
|
|