Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypt SQLite database without increasing app size?

Is there any way to encrypt the database of my android app with less increase in app size? I have tried SQLcipher, but it is increasing the size of my app by 10MB which is huge.

like image 869
Ramu Avatar asked Jul 11 '14 06:07

Ramu


People also ask

Can SQLite db be encrypted?

SQLite doesn't support encrypting database files by default. Instead, you need to use a modified version of SQLite like SEE, SQLCipher, SQLiteCrypt, or wxSQLite3.

What is the difference between SQLite and SQLCipher?

SQLCipher is an extension to SQLite, but it does not function as a loadable plugin for many reasons. Instead, SQLCipher modifies SQLite itself, and is maintained as a separate version of the source tree. SQLCipher releases are baselined against a specific source version of SQLite.

How do I protect SQLite database?

You can password protect a SQLite3 DB. Before doing any operations, set the password as follows. conn = new SQLiteConnection("Data Source=MyDatabase. sqlite;Version=3;Password=password;"); conn.

How secure is SQLite3?

SQLite is not itself encrypted. If you store text in a SQLite database, you should assume anyone with access to the device has access to the text.


2 Answers

It depends on your actual needs but a simple way would be to encrypt/decrypt the data itself before you write to / read from the database. This would have minimal impact on the apk size but there's more effort needed on your side.

If high security is required, just accept the 10MB and get on with life :-)

like image 169
Ridcully Avatar answered Sep 28 '22 05:09

Ridcully


The increase of 10MB in your APK when using SqlCipher can be avoided by shipping a separate APK for each Android architecture you want to target.

For performance and cross platform support reasons SqlCipher is implemented in C code and built as a native Android .so library using the Android NDK. A different library is built for each Android architecture it supports, which in the case of SqlCipher are:

  • armeabi
  • armeabi-v7a
  • x86

To minimize the file size increase caused by SqlCipher you can build a seperate APK that only includes the architecture that matches your users device. Take a look at the Android developers site on how to publish multiple APK's targeting different device configurations.

During my testing following this technique reduced my APK from 10MB to 4MB.

For further information this article details how to implement SqlCipher on Android and explains the file size increase.

like image 40
BrentM Avatar answered Sep 28 '22 07:09

BrentM