From e64dbe1a0e621b0f0c4fd99fbdd8a958fc77ca89 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 12 Jan 2020 17:48:28 +0000 Subject: [PATCH] Add generateKeyPair() test --- .../test/java/dev/openrs2/common/crypto/RsaTest.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/src/test/java/dev/openrs2/common/crypto/RsaTest.kt b/common/src/test/java/dev/openrs2/common/crypto/RsaTest.kt index 9f2e7232bf..24093549b9 100644 --- a/common/src/test/java/dev/openrs2/common/crypto/RsaTest.kt +++ b/common/src/test/java/dev/openrs2/common/crypto/RsaTest.kt @@ -10,6 +10,17 @@ import kotlin.test.assertEquals object RsaTest { 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 fun testEncrypt() { // from https://en.wikipedia.org/wiki/RSA_(cryptosystem)#Example