3

I have use Sqlite (sqlcipher) in my iOS project for database. In iOS 9 all things are working perfectly. Now i have update new Xcode. But DB encryption is not working now.

sqlite3 *db1;
    if (sqlite3_open([[self.databaseURL path] UTF8String], &db1) == SQLITE_OK) {
        const char* key = [g_sqlite_key UTF8String];
        AZLog(@"%s",key);
        sqlite3_key(db1, key, (int)strlen(key));
        if (sqlite3_exec(db1, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
            AZLog(@"Password is correct, or a new database has been initialized");
        } else {
            AZLog(@"Incorrect password!");
        }
        sqlite3_close(db1);
    }

Can anyone help me ?

Thanks in advance

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Nirav Patel
  • 113
  • 1
  • 5

2 Answers2

2

You have to provide readwrite and open-create permission while encryption of database using sqlcipher.

sqlite3 *db1;
    if (sqlite3_open_v2([[self.databaseURL path] UTF8String], &db1, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) == SQLITE_OK) {
        const char* key = [g_sqlite_key UTF8String];
        AZLog(@"%s",key);
        sqlite3_key(db1, key, (int)strlen(key));
        if (sqlite3_exec(db1, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
            AZLog(@"Password is correct, or a new database has been initialized");
        } else {
            AZLog(@"Incorrect password!");
        }
        sqlite3_close(db1);
    }
Nirav
  • 113
  • 1
  • 4
0

There were many changes with Xcode 8 and the new SDKs. Please refer to this guidance:

https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-new-sdks/1688

Stephen Lombardo
  • 1,503
  • 8
  • 7