Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using SQLCipher with android shipped sqlite database file

I have a database file reset in the assets file.

How can I use SQLCipher to encrypt the database in android?

like image 775
user4o01 Avatar asked May 01 '12 14:05

user4o01


2 Answers

This is going to be a bit complicated. Since the database file format is different between SQLite and SQLCipher for Android, and since you want to ship an unencrypted database, you will have to do a few things.

First, I'd get SQLiteAssetHelper going, to deliver the unencrypted database to your environment.

Then, use standard SQLCipher for Android to create an empty-but-encrypted database.

Next, you will need to implement the code to copy the data out of the packaged-but-unencrypted database and insert it into the empty-but-encrypted database.

Once that is all done, you can close and delete the packaged-but-unencrypted database and just use the encrypted one.

This might make a useful extension to SQLiteAssetHelper, someday...

like image 58
CommonsWare Avatar answered Sep 18 '22 09:09

CommonsWare


They cover how to use SQLCipher in detail on their website here

Basically you download their binaries, set them up in your project and then use their SQLiteDatabase class instead of the standard android SQLiteDatabase class.:

 import info.guardianproject.database.sqlcipher.SQLiteDatabase;
like image 21
Barak Avatar answered Sep 17 '22 09:09

Barak