Slide 30
Slide 30 text
30
private const val TRANSFORMATION = "AES/GCM/NoPadding"
private const val IV_SIZE_BYTES = 12
private const val TAG_SIZE_BITS = 128
fun decrypt(encryptedString: String): String {
val cipher = Cipher.getInstance(TRANSFORMATION)
val ivAndCiphertext = Base64.getDecoder().decode(encryptedString)
// อଘ͓͍ͯͨ͠ IV Λ༻
val spec =
GCMParameterSpec(TAG_SIZE_BITS, ivAndCiphertext, 0, IV_SIZE_BYTES)
cipher.init(Cipher.DECRYPT_MODE, getOrCreateSecretKey(), spec)
val plaintextBytes = cipher.doFinal(
/* input = */ ivAndCiphertext, /* inputOffset = */ IV_SIZE_BYTES,
/* inputLen = */ ivAndCiphertext.size - IV_SIZE_BYTES
)
return String(plaintextBytes, Charsets.UTF_8)
}