|
|
@ -10,6 +10,17 @@ import kotlin.test.assertEquals |
|
|
|
object RsaTest { |
|
|
|
object RsaTest { |
|
|
|
private const val ALLOW_UNSAFE_MOD = "org.bouncycastle.rsa.allow_unsafe_mod" |
|
|
|
private const val ALLOW_UNSAFE_MOD = "org.bouncycastle.rsa.allow_unsafe_mod" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
fun testGenerateKeyPair() { |
|
|
|
|
|
|
|
val (public, private) = Rsa.generateKeyPair() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val expectedPlaintext = BigInteger("1337") |
|
|
|
|
|
|
|
val ciphertext = Rsa.encrypt(expectedPlaintext, public) |
|
|
|
|
|
|
|
val actualPlaintext = Rsa.decrypt(ciphertext, private) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedPlaintext, actualPlaintext) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testEncrypt() { |
|
|
|
fun testEncrypt() { |
|
|
|
// from https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Example |
|
|
|
// from https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Example |
|
|
|