数据库开源框架之sqlcipher加密数据库
访问github链接:https://github.com/sqlcipher/android-database-sqlcipher
访问 http://sqlcipher.net/sqlcipher-for-android/ 查看官方介绍,
并从官方介绍中找出编译成功之后的zip压缩包进行下载
https://s3.amazonaws.com/sqlcipher/SQLCipher+for+Android+v3.1.0.zip
普通数据库
public interface MyDB {
String name = "my.db";
int version = 1;
public interface MyTable {
String name = "test";
String column_id = "_id";
String column_name = "name";
String create_sql = "create table " + name + "(" + column_id
+ " integer primary key autoincrement, " + column_name
+ " text)";
}
}
public class NativeOpenHelper extends SQLiteOpenHelper {
public NativeOpenHelper(Context ctx) {
super(ctx, MyDB.name, null, MyDB.version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(MyTable.create_sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
public class NativeDao {
private NativeOpenHelper mHelper;
public NativeDao(Context ctx) {
mHelper = new NativeOpenHelper(ctx);
}
public void add(String name) {
SQLiteDatabase database = mHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(MyTable.column_name, name);
database.insert(MyTable.name, null, values);
database.close();
}
}
经过加密的数据库
public interface SafeDB {
String name = "safe.db";
int version = 1;
public interface SafeTable {
String name = "test";
String column_id = "_id";
String column_name = "name";
String create_sql = "create table " + name + "(" + column_id
+ " integer primary key autoincrement, " + column_name
+ " text)";
}
}
public class SafeDao {
private SafeOpenHelper mHelper;
public SafeDao(Context ctx) {
mHelper = new SafeOpenHelper(ctx);
}
public void add(String name) {
SQLiteDatabase database = mHelper.getWritableDatabase("123456");
ContentValues values = new ContentValues();
values.put(SafeTable.column_name, name);
database.insert(SafeTable.name, null, values);
database.close();
}
public void query() {
SQLiteDatabase database = mHelper.getWritableDatabase("123456");
Cursor cursor = database.query(SafeTable.name,
new String[] { SafeTable.column_name }, null, null, null, null, null);
if (cursor != null) {
while (cursor.moveToNext()) {
String name = cursor.getString(0);
System.out.println(name);
}
cursor.close();
}
database.close();
}
}
import android.content.Context;
import com.loaderman.sqlitedemo.SafeDB.SafeTable; public class SafeDBHelper extends net.sqlcipher.database.SQLiteOpenHelper { public SafeDBHelper(Context ctx) {
super(ctx, SafeDB.name, null, SafeDB.version);
} @Override
public void onCreate(net.sqlcipher.database.SQLiteDatabase db) {
db.execSQL(SafeTable.create_sql);
} @Override
public void onUpgrade(net.sqlcipher.database.SQLiteDatabase arg0, int arg1,
int arg2) { } }
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//加载本地库
SQLiteDatabase.loadLibs(this);
}
public void normalDB(View view) {
NativeDao dao = new NativeDao(this);
dao.add("hahahhaha");
}
public void safeDB(View view) {
SafeDao dao = new SafeDao(this);
dao.add("hehehheheheh");
dao.query();
}
}
发现导出来的数据库文件,一个看到数据,一个看不到数据
数据库开源框架之sqlcipher加密数据库的更多相关文章
- 数据库开源框架GreenDao的使用解析
数据库开源框架GreenDao的使用解析 1,GreenDao概述 1),greenDao是一个当下十分火热的数据库开源框架,或者说是一个帮助Android开发者将数据存到SQLite中的一个开源项目 ...
- 使用SQLCipher加密数据库
Xcode中集成了免费的sqlite,但是不提供加密的模块,突然有一天,蛋疼的客户要求把数据进行加密,于是乎就寻找使用简单并且可以把数据迁移过度到加密数据库的框架. SQLCipher是第三方的开 ...
- Farseer.net轻量级开源框架 中级篇:数据库切换
导航 目 录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: 动态数据库访问 下一篇:Farseer.net轻量级开源框架 中级篇: SQL执行 ...
- Android 轻量级ORM数据库开源框架ActiveAndroid 源码分析
ActiveAndroid 项目地址在https://github.com/pardom/ActiveAndroid 关于他的详细介绍和使用步骤 可以看下面两篇文章: https://github.c ...
- 数据库开源框架之GreenDAO
主页: https://github.com/greenrobot/greenDAO 配置: 添加以下依赖 * compile 'de.greenrobot:greendao:2.1.0' * com ...
- ios开发FMDB导入SQLCipher加密数据库
转:http://www.2cto.com/kf/201407/315727.html [iOS]FMDB/SQLCipher数据库加解密,迁移
- 数据库开源框架ormlite
今天听说了ORM框架ORMLITE,特地去了解了一下. 该框架可以使用注解方式来生成数据库表,还封装了常用的数据库操作. 类似J2EE的HIBERNATE框架对数据库的处理. 省去了书写建表语句的麻烦 ...
- 数据库开源框架之litepal
主页: [https://github.com/LitePalFramework/LitePal](https://github.com/LitePalFramework/LitePal) 中文文档地 ...
- 数据库开源框架之ormlite
主页: http://ormlite.com/ 配置: 添加以下依赖 * compile 'com.j256.ormlite:ormlite-android:4.48' * compile 'com. ...
随机推荐
- BLE 5协议栈-通用访问规范层(GAP)
文章转载自:http://www.sunyouqun.com/2017/04/ 通用访问规范GAP(Generic Access Profile)是BLE设备内部功能对外的接口层,它规定了三个方面:G ...
- c++四种分配内存的方法整理
1 calloc 函数: void *calloc(unsigned int num, unsigned int size) 按照所给的数据个数和数据类型所占字节数,分配一个 num * size 连 ...
- zencart更改css按钮的宽度css buttons
includes\functions\html_output.php 大概323行的zenCssButton函数 function zenCssButton($image = '', $text, $ ...
- 实操 | 内存占用减少高达90%,还不用升级硬件?没错,这篇文章教你妙用Pandas轻松处理大规模数据
注:Pandas(Python Data Analysis Library) 是基于 NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.此外,Pandas 纳入了大量库和一些标准的数据模型 ...
- Django:新手入门学习资料汇总
(1)作者(刘江)(神都公务员出身,军工专家,文章详尽全面):http://www.liujiangblog.com/course/django/2 (2)魔力Python:作者(小楼一夜听春语)(文 ...
- NTP服务及时间同步
环境: centos7 server 192.168.2.171 client 192.168.2.173.192.168.2.174 整体思路:173.174同步171的时间,171定时同 ...
- CSS引入外部字体方法,附可用demo
有时候我们做的页面需要用到一些更好看的字体又不想用图片代替,图片会影响加载速度则使用外部字体来显示但是直接通过font-family又不一定全部都行这就需要我们在css中进行定义并且引入字体文件路径然 ...
- swoole 定时器 swoole_time_tick 和 swoole_time_after
<?php class myticker{ public $server = null; CONST host = '127.0.0.1'; CONST port = 9502; public ...
- 系统的学习Devops
系统的学习devops 1. 学习一门编程语言 Java python JavaScript 2.了解不同的操作系统概念 线程和并发,套接字,I/O管理,虚拟化,内存存储和文件系统 3.掌握终端生存大 ...
- java8 Date Localdatetime instant 相互转化(转) 及当天的最大/最小时间
Java 8中 java.util.Date 类新增了两个方法,分别是from(Instant instant)和toInstant()方法 // Obtains an instance of Dat ...