Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlcipher stopped working in iOS 10

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

like image 460
Nirav Patel Avatar asked Apr 08 '26 11:04

Nirav Patel


1 Answers

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);
    }
like image 123
Nirav Avatar answered Apr 11 '26 01:04

Nirav



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!