0
我不明白编译错误,但我的数据库不加密...SqlCipher不加密
const char* key = [@"BIGSecret" UTF8String];
int err = sqlite3_key(database, key, strlen(key));
if (sqlite3_exec(database, (const char*) "SELECT count(*) FROM animals;", NULL, NULL, NULL) == SQLITE_OK) {
// database has been initialized
}
我指网站http://sqlcipher.net/documentation/ios和利用具有AnimalDatabase.sql数据库已经在它SQLiteTutorial例子。
我也才知道现有的数据库的加密无法正常工作,所以我尝试下面的代码:
- (void)encryptDB
{
NSLog (@"Start");
sqlite3 *DB = [self getNewDBConnection];
sqlite3_exec(DB, "ATTACH DATABASE AnimalDatabase.sql AS encrypted KEY 1234;", NULL, NULL, NULL);
sqlite3_exec(DB, "CREATE TABLE encrypted.Account(id,Name,Desc,Image);", NULL, NULL, NULL);
sqlite3_exec(DB, "INSERT INTO encrypted.Account SELECT * FROM animals;", NULL, NULL, NULL);
sqlite3_exec(DB, "DETACH DATABASE encrypted;", NULL, NULL, NULL);
NSLog (@"End");
}
- (sqlite3 *)getNewDBConnection{
if (sqlite3_open([databasePath UTF8String], &newDBconnection) == SQLITE_OK) { // opening AnimalDatabase.sql
NSLog(@"Database Successfully Opened :)");
} else {
NSLog(@"Error in opening database :(");
}
return newDBconnection;
}
但仍然没有成功。谁能帮忙?