I am using SQLCipher for Android and trying to determine the correct way to check if the user password is really provided.
My first wish was to simply try to open the database with the given password using the SQLCipher SQLiteOpenHelper.getReadableDatabase(password) implementation, and then catch the SQLiteException that appears.
This works, but the problem is that since the Android API actually wraps the base C calls, it does most of the work for you - in particular, when you open the database using the Android API, it opens the database, launches its own C-level sqlite3_key method (with password provided), then tries to set the locale in the database, is the password provided correctly.
At this point, the Android library is trying to set the locale, and the underlying database throws an "encrypted or non-encrypted database" SQLiteException , which is caught and updated; but before that, an unrelated error is written to the logs, basically saying that the locale cannot be specified and the database is closed (with stack trace enabled). Since this is specifically written in the Android library, I cannot suppress it, leaving an ugly error in the logs that are not really related to my original problem, namely that I passed the wrong password.
Since level C calls are not displayed in the Android library, I canโt just use the method described in the SQLCipher API documentation regarding Key Testing , because I do not have access to open the database directly.
I SQLiteDatabaseHook to use SQLiteDatabaseHook , but as far as I can tell, this precludes my use of SQLiteOpenHelper , which does not seem to make it possible to configure the hook.
Does anyone else know a better way to verify if the SQLCipher database passphrase is decrypted correctly through the Android SQL Encryption API? I would fully expect a method call and check that an exception was thrown - I do not want the operation to try to do external processing (for example, set locale) in the database and write a completely inexpressible error to my logs.