test(core): tamper decoded ciphertext deterministically

这个提交包含在:
XuqmGroup 2026-07-27 10:19:31 +08:00
父节点 fcdc94b309
当前提交 f32e281081

查看文件

@ -4,6 +4,7 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Assert.assertTrue
import org.junit.Test
import java.util.Base64
import javax.crypto.KeyGenerator
class AesGcmCodecTest {
@ -27,7 +28,11 @@ class AesGcmCodecTest {
assertThrows(Exception::class.java) {
AesGcmCodec.decrypt(key, encoded, "scope-b".toByteArray())
}
val tampered = encoded.dropLast(1) + if (encoded.last() == 'A') "B" else "A"
val parts = encoded.split(".").toMutableList()
val cipherText = Base64.getUrlDecoder().decode(parts[2])
cipherText[cipherText.lastIndex] = (cipherText.last().toInt() xor 1).toByte()
parts[2] = Base64.getUrlEncoder().withoutPadding().encodeToString(cipherText)
val tampered = parts.joinToString(".")
assertThrows(Exception::class.java) {
AesGcmCodec.decrypt(key, tampered, "scope-a".toByteArray())
}