Search code examples
androidencryptionandroid-sqlitegreendaosqlcipher

Integrating SQLCipher with greenDAO


How to encrypt sqlite database in android with sqlchipher while using greenDao orm. I have searched this many time in SO , but didn't find any working solution .


Solution

  • In your greendao generator module add this dependency

    compile 'org.greenrobot:greendao-generator-encryption:2.2.0'
    

    So the build.gradle file your generator module will look like this

    apply plugin: 'java'
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'org.greenrobot:greendao-generator-encryption:2.2.0'
    
    }
    

    And the in your app gradle file (build.gradle module app) add these dependencies and remove all other greendao related dependencies

    compile 'org.greenrobot:greendao-encryption:2.2.2'
    compile 'net.zetetic:android-database-sqlcipher:3.5.1'
    

    and set up database like this way

      DaoMaster.EncryptedDevOpenHelper helper = new DaoMaster.EncryptedDevOpenHelper(context, "secrets.db");
      Database database = helper.getWritableDatabase("your secret key");
      DaoMaster daoMaster = new DaoMaster(database);
    

    If there is any other option to do this , please share