I am using greendao ORM. I am trying to encrypt my database using SQLCipher. Greendao automativally supports sqlcipher. So I wrote the following code for encryption.
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "encrypted-db",null);
Database db = helper.getEncryptedWritableDb("mySecretPassword");
DaoSession session = new DaoMaster(db).newSession();
return session;
However whenever I perform any database operation using this session,it gives an error
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/greenrobot/greendao/database/DatabaseOpenHelper$EncryptedHelper;
at org.greenrobot.greendao.database.DatabaseOpenHelper.checkEncryptedHelper(DatabaseOpenHelper.java:121)
at org.greenrobot.greendao.database.DatabaseOpenHelper.getEncryptedWritableDb(DatabaseOpenHelper.java:133)
My gradle dependencies are->
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'org.greenrobot:greendao:3.2.0'
compile 'com.google.code.gson:gson:2.8.0'
My proguard rules are
-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties
# If you do not use Rx:
-dontwarn rx.**
So how to encrypt my database using greendao and SQLCipher?
PS: Database db = helper.getEncryptedWritableDb("mySecretPassword");
this line generates the error on performing any database operation.
Database db = helper.getEncryptedWritableDb("mySecretPassword");
You also need to add the dependency for SQLCipher
. Add this line to your Gradle dependencies:
compile 'net.zetetic:android-database-sqlcipher:3.5.4@aar'
Source: Database Encryption
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With