Slide 9
Slide 9 text
Hiding the API Token private val iv = sha256(BuildConfig.APPLICATION_ID +
BuildConfig.VERSION_NAME)
private val key = byteArrayOf(0x00, 0x01, 0x02, 0x03, …
private val aad = byteArrayOf(0x0F, 0x0E, 0x0D, 0x0C, …
private val tag = byteArrayOf(0x85, 0xb8, 0x75, 0x61, …
private val ciphertext = byteArrayOf(0xa1, 0xd1, 0x75, …
private fun decryptSecretToken(): String {
return aes256Decrypt(iv, aad, key, ciphertext, tag)
}
private fun aes256Decrypt(
iv: ByteArray,
aad: ByteArray,
keyBytes: ByteArray,
ciphertext: ByteArray,
tag: ByteArray): String {
val cipher = Cipher.getInstance("AES/GCM/NoPadding")
val spec = GCMParameterSpec(TAG_LENGTH * 8, iv)
val key = SecretKeySpec(keyBytes, 0, keyBytes.size, "AES")
cipher.init(Cipher.DECRYPT_MODE, key, spec)
cipher.updateAAD(aad)
return String(cipher.doFinal(ciphertext + tag))
}