基于Sqlcipher和GreenDao的数据库加密

本文介绍了如何将Sqlcipher与GreenDao结合,实现Android应用中的数据库加密。主要步骤包括修改GreenDao源码,将SQLite相关类替换为Sqlcipher对应类,以及配置项目的build.gradle文件以引入依赖。此外,还提供了创建Dao工具类的示例代码,用于初始化加密数据库并获取DaoSession。
摘要由CSDN通过智能技术生成

由于需要修改源码,所以无法再通过compile 'de.greenrobot:greendao:2.0.0'来引入依赖库,下载GreenDao代码:

git clone https://github.com/greenrobot/greenDAO.git

只需要DaoCore部分即可,并且可以删除de.greenrobot.dao.test包和de.greenrobot.dao.InternalUnitTestDaoAccess.java

主要需要做如下修改:

1. android.database.sqlite.SQLiteDatabase 改为: net.sqlcipher.database.SQLiteDatabase

2. android.database.sqlite.SQLiteStatement 改为: net.sqlcipher.database.SQLiteStatement

3. android.database.DatabaseUtils 改为: net.sqlcipher.DatabaseUtils

4. de.greenrobot.dao.internal.FastCursor增加实现方法:

    @Override
    public void setExtras(Bundle extras) {
    }

由于修改量不大,对于DaoGenerator部分暂时没有研究,以后有时间再做研究,本人目前使用的是AndroidAnnotations还没有升级到butterknife,所以本次还是暂时使用它。

项目的build.gradle修改如下:

classpath 'com.android.tools.build:gradle:1.5.0'

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // 新增


在module的buid.gradle修改内容如下:

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt' // 新增

android {
    compileSdkVersion 23
    b

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值