Hi, I;m working on an iOS application. Encryption & Decryption to read & write was working till iOS 9. But after upgrade to iOS-10 it started to giving issue with following message that “file is encrypted or is not a database”.
For DB encryption I’m using following code:
sqlite3 *db1;
if (sqlite3_open([[self.databaseURL path] UTF8String], &db1) == SQLITE_OK) {
const char* key = [@"strong" UTF8String];
sqlite3_key(db1, 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(db1);
}
& it’s working perfectly fine.
For opening and reading operation I’m using following code:
-(void)openDB
{
NSString *docsDir;
docsDir = [self getDirectoryPath];
aPath = [docsDir stringByAppendingPathComponent: @"SQLITE_DEMO.sqlite"];
dbpath = [aPath UTF8String];
}
Reading:
if (sqlite3_open(dbpath, &contactDBNew) == SQLITE_OK)
{
NSString querySQL = [NSString stringWithFormat:@"SELECT FROM USER"];
const char *query_stmt = [querySQL UTF8String];
char *err;
int check = sqlite3_exec(contactDBNew, query_stmt, NULL, NULL, &err);
if (sqlite3_prepare_v2(contactDBNew, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
// Successfully executed.
} else {
// Error in execution.
}
}
Here it get failed while reading prepared statement with following error message: “file is encrypted or is not a database”.
Please suggest what I’m missing !!