我在我的iOS项目中使用Sqlite(sqlcipher)来存储数据库。在iOS 9中,所有东西都运行得很好。现在我更新了新的Xcode。但是DB加密现在还不行。
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);
}
任何人都可以帮助我吗?
提前致谢
答案 0 :(得分:2)
使用sqlcipher加密数据库时,必须提供readwrite和open-create权限。
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);
}
答案 1 :(得分:0)
Xcode 8和新SDK有很多变化。请参阅本指南:
https://discuss.zetetic.net/t/important-advisory-sqlcipher-with-xcode-8-and-new-sdks/1688