You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cipher.getOutputSize(ciphertext.size) with a ciphertext of 22 bytes using AES/GCM/NoPadding should return 6 bytes. This does not apply for devices on API version pre 29. There it is 16 bytes more (22).
Also the output buffer needs 16 more bytes than the plaintext has on Android pre 29 whereas on later Android versions like e.g. API level 29 this problem is fixed. On pre 29, when the output buffer has the expected size, a ShortBufferException is thrown.
Created a test repo to reproduce it and created a bug report too, but I don't think that Google will fix this problem anytime soon.
@Test
funworksOnAPI26() {
val input ="abcdef"// 6 bytesval key =ByteArray(16)
SecureRandom().nextBytes(key)
val cipher =Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.ENCRYPT_MODE, SecretKeySpec(key, "AES"))
val ciphertext = cipher.doFinal(input.toByteArray())
val iv = cipher.iv
cipher.init(Cipher.DECRYPT_MODE, SecretKeySpec(key, "AES"), GCMParameterSpec(128, iv))
val payloadCleartextBuf =ByteBuffer.allocate(22) // should be 6 bytesassert(
cipher.getOutputSize(ciphertext.size) ==22// // should be 6 bytes
)
val decrypted = cipher.doFinal(ByteBuffer.wrap(ciphertext), payloadCleartextBuf)
assert(decrypted ==6)
payloadCleartextBuf.flip()
println("plaintext : "+String(payloadCleartextBuf.array()))
}
@Test
funworksOnAPI30() {
val input ="abcdef"// 6 bytesval key =ByteArray(16)
SecureRandom().nextBytes(key)
val cipher =Cipher.getInstance("AES/GCM/NoPadding")
cipher.init(Cipher.ENCRYPT_MODE, SecretKeySpec(key, "AES"))
val ciphertext = cipher.doFinal(input.toByteArray())
val iv = cipher.iv
cipher.init(Cipher.DECRYPT_MODE, SecretKeySpec(key, "AES"), GCMParameterSpec(128, iv))
val payloadCleartextBuf =ByteBuffer.allocate(6)
assert(cipher.getOutputSize(ciphertext.size) ==6)
val decrypted = cipher.doFinal(ByteBuffer.wrap(ciphertext), payloadCleartextBuf)
assert(decrypted ==6)
payloadCleartextBuf.flip()
println("plaintext : "+String(payloadCleartextBuf.array()))
}
worksOnAPI30 throws the ShortBufferException on Android API level pre 29 (after removing the assertions otherwise the assertion will fail before).
The text was updated successfully, but these errors were encountered:
cipher.getOutputSize(ciphertext.size)
with a ciphertext of 22 bytes usingAES/GCM/NoPadding
should return 6 bytes. This does not apply for devices on API version pre 29. There it is 16 bytes more (22).Also the output buffer needs 16 more bytes than the plaintext has on Android pre 29 whereas on later Android versions like e.g. API level 29 this problem is fixed. On pre 29, when the output buffer has the expected size, a
ShortBufferException
is thrown.Created a test repo to reproduce it and created a bug report too, but I don't think that Google will fix this problem anytime soon.
worksOnAPI30
throws theShortBufferException
on Android API level pre 29 (after removing the assertions otherwise the assertion will fail before).The text was updated successfully, but these errors were encountered: