0

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
  1. Opening the database in DB Browser for SQLite with the same passphrase (worked fine on a lower version of SQLCipher).
  2. Ensuring passphrase correctness by logging it in the app (storeHelper.getStoreValue()).
  3. Attempting to migrate the database format but still facing the same error.

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.