将SQLCipher与greenDAO集成 [英] Integrating SQLCipher with greenDAO

查看:456
本文介绍了将SQLCipher与greenDAO集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在使用greenDao orm时使用sqlchipher在android中加密sqlite数据库.我已经在SO中搜索了很多次,但是没有找到任何可行的解决方案.

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 .

推荐答案

在greendao生成器模块中添加此依赖项

In your greendao generator module add this dependency

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

因此,生成器模块的 build.gradle 文件将如下所示

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'

}

然后在您的应用gradle文件( build.gradle 模块应用)中添加这些依赖关系,并删除所有其他与greendao相关的依赖关系

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

这篇关于将SQLCipher与greenDAO集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆