Skip to content

Commit 0f7f94f

Browse files
authored
fix: add error handling in decryptBytes to throw CryptoFailedException for AEADBadTagException (#739)
1 parent e1a54b5 commit 0f7f94f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

android/src/main/java/com/oblador/keychain/cipherStorage/CipherStorageBase.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ abstract class CipherStorageBase(protected val applicationContext: Context) : Ci
339339

340340
/** Decrypt provided bytes to a string. */
341341
@SuppressLint("NewApi")
342-
@Throws(GeneralSecurityException::class, IOException::class)
342+
@Throws(GeneralSecurityException::class, IOException::class, CryptoFailedException::class)
343343
protected open fun decryptBytes(
344344
key: Key,
345345
bytes: ByteArray,
@@ -361,7 +361,14 @@ abstract class CipherStorageBase(protected val applicationContext: Context) : Ci
361361
e.cause?.message?.contains("Key user not authenticated") == true -> {
362362
throw UserNotAuthenticatedException()
363363
}
364-
364+
e is javax.crypto.AEADBadTagException -> {
365+
throw CryptoFailedException(
366+
"Decryption failed: Authentication tag verification failed. " +
367+
"This usually indicates that the encrypted data was modified, corrupted, " +
368+
"or is being decrypted with the wrong key.",
369+
e
370+
)
371+
}
365372
else -> throw e
366373
}
367374
}

0 commit comments

Comments
 (0)