Reputation: 468
SQLCipher website mentions
"Init the database in onCreate() using SQLiteDatabase.loadLibs(this); //first init the db libraries with the context"
I am calling this loadlibs only once in my first activity (seems to be working). I want to make sure I do not need to call this function for every activity that might access the database. Is this correct?
How do I change the database password? I tried rekey but that does not work. It still takes the old password.
Any help would be appreciated.
Thank you.
Upvotes: 2
Views: 3496
Reputation: 10482
SQLiteDatabase.rawExecSQL("PRAGMA key = 'old_password';");
SQLiteDatabase.rawExecSQL("PRAGMA rekey = 'new_password';");
Upvotes: 6
Reputation: 1388
Yes, that is correct - you only need to call SQLiteDatabase.loadLibs(...);
once as that is responsible for loading the various native libraries SQLCipher for Android uses at runtime into the process. To change the password, you must first have a reference to a SQLiteDatabase
object where you have provided the original password. Once you have that you can issue PRAGMA rekey = 'some new password';
using execSQL(...);
. More information regarding the rekey command can be found here.
Upvotes: 4