Net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: create locale table failed in Android



I am using SQLCipher for database encryption in using SQLCipher. I am used to get exceptions in call to getWritableDatabase(). This issue happens very randomly, but easily reproducible in any android device if we try 5-10 times. The issue starts appearing after I changed the key generation method. I am using Android Key Store for generating the password as android dev guide. Before using new Android Keystore mechanism, I was using Java KeyGenerator, which does not lead the exception. Below is the stack trace:

E/AndroidRuntime(16077): net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: create locale table failed
E/AndroidRuntime(16077): at net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method)
E/AndroidRuntime(16077): at net.sqlcipher.database.SQLiteDatabase.setLocale(
E/AndroidRuntime(16077): at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(
E/AndroidRuntime(16077): at net.sqlcipher.database.SQLiteDatabase.openDatabase(
E/AndroidRuntime(16077): at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(
E/AndroidRuntime(16077): at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(

  I tried putting logs in JNI files to check if passwork generated / sent to SQLCipher correctly, which seems absolutely fine. Can anyone please suggest something on it.



Hi @ndeka

I would suggest logging the key value you are providing the database connection to see what value is being provided each time.


Hi ,

Thanks. I am printing the key value in my application as well as tried printing in JNI function (native_key_char). But the it is the same. The key value is different per installation.



Hi @ndeka

If that key is causing an issue on device, please pull the database off the device and try to open the database with the SQLCipher command line shell. Please let us know if you are able to access the content on the database locally.


Hi @developernotes,

I am able to find out the problem. The exception is coming as our application is trying to open the database twice with two different passwords. So after extracting the database, I am able to unlock the DB with first password, but not with second. So there should not be any problem with SQLCipher library, we will look into our encryption mechanism. Thanks a lot for your help.


Hi @ndeka

Thank you for getting back to us, we are glad to hear you were able to isolate the issue. Take care!