|
|
@ -51,34 +51,34 @@ object RsaTest { |
|
|
|
val (public, private) = Rsa.generateKeyPair(Rsa.CLIENT_KEY_LENGTH) |
|
|
|
val (public, private) = Rsa.generateKeyPair(Rsa.CLIENT_KEY_LENGTH) |
|
|
|
|
|
|
|
|
|
|
|
val expectedPlaintext = BigInteger("1337") |
|
|
|
val expectedPlaintext = BigInteger("1337") |
|
|
|
val ciphertext = Rsa.encrypt(expectedPlaintext, public) |
|
|
|
val ciphertext = Rsa.crypt(expectedPlaintext, public) |
|
|
|
val actualPlaintext = Rsa.decrypt(ciphertext, private) |
|
|
|
val actualPlaintext = Rsa.crypt(ciphertext, private) |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(expectedPlaintext, actualPlaintext) |
|
|
|
assertEquals(expectedPlaintext, actualPlaintext) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testEncrypt() { |
|
|
|
fun testEncrypt() { |
|
|
|
val ciphertext = Rsa.encrypt(BigInteger("65"), PUBLIC_KEY) |
|
|
|
val ciphertext = Rsa.crypt(BigInteger("65"), PUBLIC_KEY) |
|
|
|
assertEquals(BigInteger("2790"), ciphertext) |
|
|
|
assertEquals(BigInteger("2790"), ciphertext) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testDecrypt() { |
|
|
|
fun testDecrypt() { |
|
|
|
val ciphertext = Rsa.decrypt(BigInteger("2790"), PRIVATE_KEY) |
|
|
|
val ciphertext = Rsa.crypt(BigInteger("2790"), PRIVATE_KEY) |
|
|
|
assertEquals(BigInteger("65"), ciphertext) |
|
|
|
assertEquals(BigInteger("65"), ciphertext) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testDecryptCrt() { |
|
|
|
fun testDecryptCrt() { |
|
|
|
val ciphertext = Rsa.decrypt(BigInteger("2790"), PRIVATE_KEY_CRT) |
|
|
|
val ciphertext = Rsa.crypt(BigInteger("2790"), PRIVATE_KEY_CRT) |
|
|
|
assertEquals(BigInteger("65"), ciphertext) |
|
|
|
assertEquals(BigInteger("65"), ciphertext) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testEncryptByteBuf() { |
|
|
|
fun testEncryptByteBuf() { |
|
|
|
wrappedBuffer(65).use { plaintext -> |
|
|
|
wrappedBuffer(65).use { plaintext -> |
|
|
|
plaintext.rsaEncrypt(PUBLIC_KEY).use { ciphertext -> |
|
|
|
plaintext.rsaCrypt(PUBLIC_KEY).use { ciphertext -> |
|
|
|
wrappedBuffer(10, 230.toByte()).use { expectedCiphertext -> |
|
|
|
wrappedBuffer(10, 230.toByte()).use { expectedCiphertext -> |
|
|
|
assertEquals(expectedCiphertext, ciphertext) |
|
|
|
assertEquals(expectedCiphertext, ciphertext) |
|
|
|
} |
|
|
|
} |
|
|
@ -89,7 +89,7 @@ object RsaTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
fun testDecryptByteBuf() { |
|
|
|
fun testDecryptByteBuf() { |
|
|
|
wrappedBuffer(10, 230.toByte()).use { ciphertext -> |
|
|
|
wrappedBuffer(10, 230.toByte()).use { ciphertext -> |
|
|
|
ciphertext.rsaDecrypt(PRIVATE_KEY).use { plaintext -> |
|
|
|
ciphertext.rsaCrypt(PRIVATE_KEY).use { plaintext -> |
|
|
|
wrappedBuffer(65).use { expectedPlaintext -> |
|
|
|
wrappedBuffer(65).use { expectedPlaintext -> |
|
|
|
assertEquals(expectedPlaintext, plaintext) |
|
|
|
assertEquals(expectedPlaintext, plaintext) |
|
|
|
} |
|
|
|
} |
|
|
|