AI Integration Quick Reference
AI Integration Quick Reference
encryption(true). The minimum SDK version is 5.1.0.
Encryption covers the message database only. Downloaded media files (photos, voice notes, documents) stay as ordinary unencrypted files on disk, because their local paths are handed to native image and video loaders. See What is and isn’t encrypted.
Add the SQLCipher dependency
The SDK does not bundle the cipher engine, so apps that do not use encryption pay none of its size (roughly 3 MB per ABI) and the SDKminSdk stays 21. If you enable encryption you must add the engine yourself:
Turn on encryption
Setencryption(true) on the OfflineConfig you pass to the SDK during initialization (see Enable Offline Support).
- Java
- Kotlin
Choose what happens when encryption cannot run
encryptionFailureBehavior decides what the cache does when encryption cannot be applied at all on this build or device — for example the SQLCipher dependency is missing, the native library will not load, or there is no supported ABI. It governs only that case: a transient failure still retries, and a lost or wrong key self-heals by wiping and rebuilding the cache encrypted.
Key storage
You do not supply or manage the encryption key. The SDK generates a random 32-byte key, one per app ID and logged-in user (UID), wraps it with a non-exportable Android Keystore key, and stores the wrapped blob in the app’s no-backup files directory. The key never leaves the device and is never returned by any API. If the key is lost or the stored database no longer matches it, the cache resets and rebuilds — see Cache resets.Check encryption status
CometChat.getOfflineEncryptionStatus() returns an OfflineEncryptionStatus describing what encryption is actually doing — never what was merely requested. It is safe to call at any time and never returns the key or any part of it.
- Java
- Kotlin
What gets encrypted
Media bytes live outside the database because
Attachment.getLocalPath() is public API and those paths are passed straight to native media loaders. “Encrypted at rest” here always means the message database, never the media cache.
Cache resets on key loss
If the key can no longer decrypt the stored database, the SDK wipes the local cache and rebuilds it encrypted — it never silently falls back to plaintext for a cache that could be encrypted. Any unsent messages still queued in the outbox at that point are lost. They lived inside the unreadable database, so they cannot be counted or reported one by one:pendingMessagesLost is OfflineCacheResetListener.PENDING_COUNT_UNKNOWN (-1). When the reset is ENCRYPTION_CHANGED instead, each queued message fails with reason DISCARDED and pendingMessagesLost is the exact count, unless the old database could not be read.
Register an OfflineCacheResetListener to be told when this happens:
- Java
- Kotlin
KEY_LOST, WRONG_KEY, CORRUPTED, ESCALATED, and ENCRYPTION_CHANGED (you turned encryption on or off between launches, which also discards any queued messages and the cached media). See Stay in Sync for the full cache-reset flow and the complete list of reasons, and the API Reference for every field and enum.