encrypt sqlite with sqlcipher
##Get the sqlcipher SourceCode
1 | #使用2.1的版本比较稳定些 |
##Complite the source code
动态链接的编译方法(Compiling with dynamic linking)[推荐]:
1 | ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto" |
静态库的编译方法: (replace /path/to with the path to libcrypto.a)
1 | #./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="/path/to/libcrypto.a" |
##How to encrypt a sqlite(In Shell)
#加密数据库几种方式
####1.shell方式加密一个sqlite
1 | sqlcipher test.db |
####2.(In shell)
1 | sqlciper test.db |
#####3..Object-c代码实现对一个非加密库导入到加密库的方法(已经验证)(Xcode)
1 | NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0]; |
#为加密数据库解密
####1.先导出现有库的数据(In shell)
1 | sqlcipher plaintext.db |
####将新的数据库导出,并加密,之后导入非加密的库里面的数据
1 | sqlcipher another.db |
####2. 为加密后的sqlite执行解密(其实步骤与加密一样,只要把key设置为空就实现了不加密)
1 | ATTACH DATABASE 'encrypted.db' as encrypted KEY ''; //encrypted.db是要导出的新的数据库 |
####3.(In shell)
1 | sqlciper test.db |
##参考
- sqlcipher配置 http://sqlcipher.net/ios-tutorial/
- sqlcipher API http://sqlcipher.net/sqlcipher-api/
- sqlcipher 使用 http://jordy.easymorse.com/?p=970
- Mac SQLCipher导出工具 https://github.com/welsonla/SQLCipherExport
encrypt sqlite with sqlcipher
http://welsonla.timebot.net/2013/08/13/encrypt-sqlite-with-sqlcipher/