I dont get compile errors, but my database does not encrypt...
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
}
I am referring site http://sqlcipher.net/documentation/ios and using SQLiteTutorial example which has AnimalDatabase.sql database already in it.
I also came to know that encryption wont work on the existing database, so i tried the below code:
- (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;
}
But still no success. Can anyone help?