在podfile文件中加入
pod
'FMDB/SQLCipher'
#此处只能这样加入,分开(pod
'FMDB' pod
'SQLCipher')加密无效。。。(亲试)至于原因暂时还不清楚,知道的同学希望能告知下,谢谢
pod
'LKDBHelper'
加密的时候 数据库不能有数据
LKDBHelper的作者已经提供了方法,只需要设置key就可以实现加密了
- (
BOOL)setKey:(
NSString *)key;
- (
BOOL)rekey:(
NSString *)key;
在创建完 LKDBHelper 就要设置key
+(LKDBHelper *)getUsingLKDBHelper
{
static LKDBHelper* db;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *paths = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,
YES) firstObject];
NSString* dbpath = [paths stringByAppendingPathComponent:[
NSString stringWithFormat:@
"userInfos/test.db"]];
NSLog(@
"数据库路径------->%@",dbpath);
db = [[LKDBHelper alloc] initWithDBPath:dbpath];
[db setKey:@
"encryption"];
});
return db;
}
转载请注明原文地址: https://ju.6miu.com/read-668632.html