Add encrypted notification log storage foundation

This commit is contained in:
ajp_anton
2026-07-23 08:03:19 +00:00
parent 022fb5220f
commit 23af171c29
6 changed files with 271 additions and 0 deletions
@@ -0,0 +1,29 @@
package se.ajpanton.notificationlog.data
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.security.SecureRandom
import javax.crypto.KeyGenerator
class AesGcmCipherTest {
@Test
fun roundTripsDataWithoutLeavingItInCipherText() {
val key = KeyGenerator.getInstance("AES").apply { init(256) }.generateKey()
val plainText = "private notification content".encodeToByteArray()
val encrypted = AesGcmCipher(key).encrypt(plainText)
assertFalse(encrypted.cipherText.decodeToString().contains("private notification content"))
assertTrue(AesGcmCipher(key).decrypt(encrypted).contentEquals(plainText))
}
@Test(expected = javax.crypto.AEADBadTagException::class)
fun rejectsTamperedCipherText() {
val key = KeyGenerator.getInstance("AES").apply { init(256) }.generateKey()
val encrypted = AesGcmCipher(key, SecureRandom()).encrypt("message".encodeToByteArray())
encrypted.cipherText[0] = (encrypted.cipherText[0].toInt() xor 1).toByte()
AesGcmCipher(key).decrypt(encrypted)
}
}