Skip to content

Commit

Permalink
test(symmetric): tests for decrypting with invalid keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdcruz committed Jul 28, 2023
1 parent 8536a8a commit 5113491
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package io.github.jhdcruz.kipher.symmetric

import io.github.jhdcruz.kipher.symmetric.SymmetricTestParams.aad
import io.github.jhdcruz.kipher.symmetric.SymmetricTestParams.invalidKey
import io.github.jhdcruz.kipher.symmetric.SymmetricTestParams.message
import io.github.jhdcruz.kipher.symmetric.aes.AesCBC
import io.github.jhdcruz.kipher.symmetric.aes.AesGCM
Expand All @@ -28,7 +30,7 @@ internal class BaseSymmetricTest {
val aesCbc = AesCBC()

assertThrows<InvalidAlgorithmParameterException> {
aesCbc.encrypt(message, SymmetricTestParams.invalidKey)
aesCbc.encrypt(message, invalidKey)
}
}

Expand All @@ -37,7 +39,27 @@ internal class BaseSymmetricTest {
val aesGcm = AesGCM()

assertThrows<InvalidAlgorithmParameterException> {
aesGcm.encrypt(message, SymmetricTestParams.invalidKey, SymmetricTestParams.aad)
aesGcm.encrypt(message, invalidKey, aad)
}
}

@Test
fun `test standard decryption with invalid secret key`() {
val aesCbc = AesCBC()
val encrypted = aesCbc.encrypt(message)

assertThrows<InvalidAlgorithmParameterException> {
aesCbc.decrypt(encrypted["data"]!!, invalidKey)
}
}

@Test
fun `test authenticated decryption using invalid secret key`() {
val aesGcm = AesGCM()
val encrypted = aesGcm.encrypt(message, aad)

assertThrows<InvalidAlgorithmParameterException> {
aesGcm.decrypt(encrypted["data"]!!, invalidKey, encrypted["aad"]!!)
}
}

Expand Down

0 comments on commit 5113491

Please sign in to comment.