Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get started with SQLCipher for android?

I need to use SQLCipher for android...i've already made my app using SQLite and want to just convert it to SQLCipher.

The problem is, I know nothing about SQLCipher.

I have read about it in this link: http://sqlcipher.net/sqlcipher-for-android/

But i'm not too clear, still. I was wondering if you could provide some basic sqlcipher for android tutorials, where everything is taught in an easy way from the absolute basics.

Thanks!

like image 547
Randomly Named User Avatar asked Jul 16 '13 08:07

Randomly Named User


People also ask

How do I use SQLCipher?

For use with dotConnect for SQLite, it must be renamed to sqlite3. dll. To connect to SQLCipher encrypted database, you should set the Encryption connection string parameter to SQLCipher and specify the Password and Encryption License Key connection string parameters.

What is SQLCipher encryption?

SQLCipher is a security extension to the SQLite database platform that facilitates the creation of encrypted databases. It uses the internal SQLite Codec API to insert a callback into the pager system that can operate on database pages immediately before they are written to and read from storage.


Video Answer


2 Answers

To properly use SQL Cipher for Android you must use external libraries and change some of the code which interacts with your DB.

  1. These must first be added to your project (within the libs folder.) Refer here to get these: http://sqlcipher.net/sqlcipher-for-android/

  2. Secondly you need to add the icudt4dl.zip file to your assets folder, this Zip comes with the SQL Cipher libraries.

  3. Right click your project, go to properties then Java build path then include libraries such as commons-codec.jar, guava-r09.jar, sqlcipher.jar. Once this is done, do a build clean.

  4. Then within your App, instead of importing android.database.sqlite, you will import import net.sqlcipher.database

  5. Change any code which interacts with the DB, example:

    SQLiteDatabase.loadLibs(context);

    String dbPath = this.getDatabasePath("dbname.db").getPath();

    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbPath,"dbPassword", null);

  6. Verify that the database is encrypted, go to DDMS perspective in Eclipse, click the file explorer tab, navigate to data/data/, click on the .db file and select get device file, save it to your desktop and open it with a text editor. Look for the plain text values you have been inserting into your database, if you can still read them, something has gone wrong.

It might also be a good idea to check out some SQLite tutorials before implementing SQL Cipher. A good one is mentioned here: Android sqlite database - where do i start as the tutorial has gone for notepad?

Update

This answer is outdated now and Eclipse is practically deprecated for Android Development. I recently had to build an app using SQLCipher on Android Studio for Android 5 + 6 and these are the steps I followed.

In Android Studio, you can include SQLCipher as a dependency in your build file. Update your dependencies in build gradle to include the following line:

dependencies{
    compile 'net.zetetic:android-database-sqlcipher:3.5.4@aar'
}

You can keep up to date with versions here: https://mvnrepository.com/artifact/net.zetetic/android-database-sqlcipher

My App wouldn't build unless I removed the SQLCipher files in the lib folder and the asset folder, but after that it worked as expected. Once you made these changes, run a build/clean and check if it works.

The same steps mentioned above with changing your code still stand.

like image 174
SeanD Avatar answered Oct 23 '22 20:10

SeanD


While you can still follow Zetetic's Eclipse tutorial and add .so libraries yourself, you really don't need to do it in Android Studio. Just add a Gradle dependency, like compile net.zetetic:android-database-sqlcipher:3.3.1-2@aar and you're ready to go!

Here you can always check the latest aar version and here you can read more about integration.

like image 9
lomza Avatar answered Oct 23 '22 19:10

lomza