forked from openrs2/openrs2
parent
0bb0d1a5b6
commit
84b384156f
@ -0,0 +1,14 @@ |
||||
package dev.openrs2.common |
||||
|
||||
import com.google.inject.AbstractModule |
||||
import com.google.inject.Scopes |
||||
import dev.openrs2.common.crypto.RsaKeyProvider |
||||
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters |
||||
|
||||
class CommonModule : AbstractModule() { |
||||
override fun configure() { |
||||
bind(RSAPrivateCrtKeyParameters::class.java) |
||||
.toProvider(RsaKeyProvider::class.java) |
||||
.`in`(Scopes.SINGLETON) |
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
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") |
||||
} |
||||
} |
@ -0,0 +1 @@ |
||||
/private.key |
Loading…
Reference in new issue