-1

I've been using unecrypted data base so far in my app and now I wanted to migrated my database to encrypted database using SQLCipher. Here is my situation.

For the next release I'll update the database version and that will execute the script. For the onUpgrade() to be called I've to call geReadableDatabase() or getWriteableDatabase(). So when I'll called for any operation() it will execute my script and that will do the following operation.

  1. Create and encrypted database.

  2. Export data from the old (un-encrypted) database to the encrypted database.

  3. Delete the old database.

So when I'll perform the migration I'll like to halt all the other operation until the migration is complete and then halted operation will be performed on the encrypted database.

Not really sure how can I achieve that so what approach should I use to achieve this.

user2934930
  • 1,076
  • 2
  • 12
  • 26

1 Answers1

0

I think what you are searching for is sqlcipher_export method

It easly facilitates copying unencrypted DB to the encrypted one. On Android probably you could do something like:

unencryptedDb.rawExecSQL("ATTACH DATABASE 'secure_db_name.db' AS encrypted KEY 'testkey'");
unencryptedDb.rawExecSQL("SELECT sqlcipher_export('secure_db_name')");
unencryptedDb.rawExecSQL("DETACH DATABASE secure_db_name");