$ git clone https://github.com/sqlcipher/sqlcipher.git
Select the Build Settings pane. In the search field, type in "Header Search Paths". Double-click on the field under the target column and add the following path: $(PROJECT_DIR)/sqlcipher/src
Start typing "Other Linker Flags" into the search field until the setting appears, double click to edit it, and add the following value: $(BUILT_PRODUCTS_DIR)/libsqlcipher.a
Start typing "Other C Flags" into the search field until the setting appears, double click to edit it, and in the pop-up add the following value: -DSQLITE_HAS_CODEC
Expand Target Dependencies and click on the + button at the end of the list. In the browser that opens, select the sqlcipher static library target:
Integration to open database using password.
-(void)checkAndOpenDB{
sqlite3 *db;
NSString *strPassword = @"password";
if (sqlite3_open_v2([[databaseURL path] UTF8String], &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) == SQLITE_OK) {
const char* key = [strPassword UTF8String];
sqlite3_key(db, key, (int)strlen(key));
if (sqlite3_exec(db1, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
NSLog(@"Password is correct, or a new database has been initialized");
} else {
NSLog(@"Incorrect password!");
}
sqlite3_close(db);
}
}
- (NSURL *)databaseURL
{
NSArray *URLs = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
NSURL *directoryURL = [URLs firstObject];
NSURL *databaseURL = [directoryURL URLByAppendingPathComponent:@"database.sqlite"];
return databaseURL;
}