Integrating SQLCipher with greenDAO

允我心安 提交于 2019-12-24 09:35:07

问题


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 .


回答1:


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



来源:https://stackoverflow.com/questions/39637546/integrating-sqlcipher-with-greendao

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!