I am working with SQLCipher to encrypt my database in my Android app, but I am facing an issue where I cannot open the database using the correct passphrase. When I attempt to query the database, I encounter the following exception:
android.database.sqlite.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;
Scenario: I am pushing an update to an existing app. When the user tries to update and install the app, it crashes immediately after launching. Here is the relevant code snippet I am using to open the database:
val passphrase: ByteArray = SQLiteDatabase.getBytes(pw.toCharArray())
val factory = SupportFactory(passphrase)
val db = Room.databaseBuilder(application, AppDatabase::class.java, "TEMPDB")
.openHelperFactory(factory)
.build()
Database Setup:
- I am using SQLCipher for encryption.
- The database version is 4 (databaseVersion = 4).
- When debugging, I confirmed that the passphrase is correct.
Steps I’ve Already Taken:
- I added PRAGMA cipher_migrate; but it still crashes.
- I have tried checking the database on the device using Device File Explorer, but I get the same error.
- I have verified that the database file exists under /data/data/YOUR_PACKAGE_NAME/databases/.
- I have tried testing with different versions of SQLCipher but without success.
My Environment:
- SQLCipher version: 4.x
- AGP version: 8.x.x
- Android SDK: SDK 35
- Room Database with SQLCipher
- Opening the database in DB Browser for SQLite with the same passphrase (worked fine on a lower version of SQLCipher).
- Ensuring passphrase correctness by logging it in the app (storeHelper.getStoreValue()).
- Attempting to migrate the database format but still facing the same error.