SqlCipher does not encrypt
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开发者_JAVA技巧);
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?
The most likely problem is that you aren't linking your project against the SQLCipher static library. Thus, your project is using the default system SQLite framework.
Go into your Project Build settings -> Build Phases -> Link With Binary Libraries and make sure that libsqlcipher.a and libcrypto.a are both listed there. If not, add them. Then clean the project and the rebuild.
精彩评论