Database encryption
Right now KittyORM has no built-in functionality to provided partial or full database encryption. In future there are plans to implement AES128\256 partial encryption but what if you want to encrypt your database right now? You can use third-party solutions for this. For example, you can use such great solution as SQLCipher. So, you want to encrypt your KittyORM database with SQLCipher. Here some steps to take:
- Integrate SQLCipher into your project. For example, use this tutorial to do that: SQLCipher for Android Application Integration.
- Get KittyORM library sources from KittyORM GitHub repository and add it to your project apart with your java sources or as AndroidStudio library module.
- Change all imports at KittyORM that import Android database classes to corresponding classes of SQLCipher. You can do it manually or run this script at KittyORM sources directory:
#!/bin/bash find . -name '*.java' -exec sed -i -e 's/android.database.sqlite/net.sqlcipher.database/g' {} \; find . -name '*.java' -exec sed -i -e 's/android.database/net.sqlcipher/g' {} \;
- Modify some methods of
KittyDatabaseHelper.class
for adding support of database encryption.Click to view modified methods of
KittyDatabaseHelper.class
with encryption support:1public SQLiteDatabase getWritableDatabase(String pwd) { 2 return super.getWritableDatabase(pwd); 3} 4 5public SQLiteDatabase getReadableDatabase(String pwd) { 6 return super.getReadableDatabase(pwd); 7} 8
- Modify constructor of
KittyDatabase.class
for adding support of database encryption.Click to view modified constructor of
KittyDatabaseHelper.class
with encryption support:1public KittyDatabase(Context ctx, String databasePassword) { 2 net.sqlcipher.database.SQLiteDatabase.loadLibs(ctx); 3 4 ... // Old constructor code 5} 6
- And, in theory, you are ready to use KittyORM with SQLCipher. Just initialize your KittyORM database implementation using
public KittyDatabase(Context ctx, String databasePassword)
constructor. However, nobody yet tested this integration :)