I used SQLCipher to encrypt sqlite database in my app.everything is ok but my app runs slow during fetching database.i changed PRAGMA kdf_iter to 4000 and it's still slow.before encryption i don't have any problem.
-(NSError *) openDatabase {
NSError *error = nil;
NSString *databasePath = [self getDatabasePath];
const char *dbpath = [databasePath UTF8String];
int result = sqlite3_open_v2 (dbpath, &db , SQLITE_OPEN_READWRITE , NULL);
if (result == SQLITE_OK) {
sqlite3_exec(db, [@"PRAGMA kdf_iter = '4000';" UTF8String], NULL, NULL, NULL);
sqlite3_exec(db, [@"PRAGMA key = 'password'" UTF8String], NULL, NULL, NULL);
NSLog(@"Password is correct , Database is Activated");
sqlite3_exec(db, [@"PRAGMA cipher = 'aes-256-cfb';" UTF8String], NULL, NULL, NULL);
}
else {
NSLog(@"Incorrect password!");
}
if (result != SQLITE_OK) {
const char *errorMsg = sqlite3_errmsg(db);
NSString *errorStr = [NSString stringWithFormat:@"The database could not be opened: %@",[NSString stringWithCString:errorMsg encoding:NSUTF8StringEncoding]];
error = [self createDBErrorWithDescription:errorStr andCode:kDBFailAtOpen];
}
return error;
}
SQLCipher does not implement its own encryption. Instead it uses the widely available encryption libraries like OpenSSL libcrypto, LibTomCrypt, and CommonCrypto for all cryptographic functions.
SQLCipher is an open source library that provides transparent, secure 256-bit AES encryption of SQLite database files.
Finally i could optimize my SQLCipher performance with Nick Parker useful guidance.
As he said:
There are a few very important guidelines for optimal SQLCipher performance:
To diagnose performance problems with specific query statements, it may be helpful to run an explain query plan command against specific queries.
If you are uncertain of what queries are performing poorly, SQLCipher includes a pragma called cipher_profile that allows for profiling queries and their respective execution time in milliseconds.
This is the Reference Link
Many thanks to Nick Parker.
Also this blog was very useful for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With