Android使用的是开源的SQLite数据库,数据库本身没有加密,加密思路通常有两个:
1. 对几个关键的字段使用加密算法,再存入数据库
2. 对整个数据库进行加密
SQLite数据库加密工具:
收费工具:
免费工具:
SQLCipher使用:
SQLCipher是完全开源的软件,提供256-bit AES加密
源码编译:
1. OpenSSL编译
SQLCipher源码编译需要依赖OpenSSL提供的libcrypto
下载OpenSSL源码,这里选择稳定版本1.0.1h
1 openssl-1.0.1h Admin$ ./config --prefix=/usr/local --openssldir=/usr/local/openssl2 openssl-1.0.1h Admin$ make
3 openssl-1.0.1h Admin$ maketest4 openssl-1.0.1h Admin$ make install
2. SQLCipher源码编译
1 sqlcipher Admin$ ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="/usr/local/lib/libcrypto.a"
2 sqlcipher Admin$ make
命令行使用:
1. 创建加密数据库
1 $ sqlcipher encrypted.db2 SQLCipher version 3.8.4.3 2014-04-03 16:53:12