如何使用SQLCipher给FMDB的数据库加密?
2015-11-04 23:21
288 查看
使用代码:
可以下载SQLCipher。下载完之后,找到FMDatabase.m文件,在特定位置插入代码:
1、#define DB_SECRETKEY @”secretkey”
2、[self setKey:DB_SECRETKEY];(open方法加入)
3、[self setKey:DB_SECRETKEY];(openWithFlags方法加入)
具体如下:
顺便说下,修改代码的时候,可能涉及到解锁。那文件怎么重新加锁?
1、在文件夹中找到那个文件的位置。
2、选中那个文件,右键点击“显示简介”。
3、在“通用”底下,找到“已锁定”,点击“已锁定”就行了。
pod 'FMDB/SQLCipher'
可以下载SQLCipher。下载完之后,找到FMDatabase.m文件,在特定位置插入代码:
1、#define DB_SECRETKEY @”secretkey”
2、[self setKey:DB_SECRETKEY];(open方法加入)
3、[self setKey:DB_SECRETKEY];(openWithFlags方法加入)
具体如下:
#define DB_SECRETKEY @"secretkey" - (BOOL)open { if (_db) { return YES; } int err = sqlite3_open([self sqlitePath], &_db ); if(err != SQLITE_OK) { NSLog(@"error opening!: %d", err); return NO; } else { [self setKey:DB_SECRETKEY]; } if (_maxBusyRetryTimeInterval > 0.0) { // set the handler [self setMaxBusyRetryTimeInterval:_maxBusyRetryTimeInterval]; } return YES; } #if SQLITE_VERSION_NUMBER >= 3005000 - (BOOL)openWithFlags:(int)flags { if (_db) { return YES; } int err = sqlite3_open_v2([self sqlitePath], &_db, flags, NULL /* Name of VFS module to use */); if(err != SQLITE_OK) { NSLog(@"error opening!: %d", err); return NO; } else { [self setKey:DB_SECRETKEY]; } if (_maxBusyRetryTimeInterval > 0.0) { // set the handler [self setMaxBusyRetryTimeInterval:_maxBusyRetryTimeInterval]; } return YES; } #endif
顺便说下,修改代码的时候,可能涉及到解锁。那文件怎么重新加锁?
1、在文件夹中找到那个文件的位置。
2、选中那个文件,右键点击“显示简介”。
3、在“通用”底下,找到“已锁定”,点击“已锁定”就行了。
相关文章推荐
- Oracle练习题20~33
- MongoDB副本集搭建和测试
- MYSQL数据类型
- mysql基础理论及通用二进制方式安装
- mysql-proxy读写分离测试
- MySQL 5.7.9 GA新特性
- mysql导入导出
- mongodb linux 64位下载
- 在数据库中使用CLOB存储
- Oracle Create DBLink
- dos进入mysql
- mecache安装与php_memcache.dll扩展
- RMAN - duplicate DATABASE
- Oracle数据库安装图解
- 转SQL Server 的事务和锁
- mysql脚本
- Redis学习手册(Set数据类型)
- sql之left join、right join、inner join的区别(转)
- mongodb 性能测试
- mysql上的加密算法