I'm currently working on a simple account management app for the iPhone. I'm using sqlcipher to encrypt and decrypt the database.
Currently i have an unencrypted database in the application bundle, which i want to either copy to the iPhone document directory and then get it encrypted, or get it encrypted before i copy it over to the document directory.
The problem that i'm facing is that no matter what i do, i seem to get an unencrypted database, no matter what method of encryption i try to use, be it the "ATTACH" database method or the "key()/rekey()" method.
I tried using the "ATTACH" database method in terminal but the result was an unencrypted database. I tried using the "key()/rekey()" method programmatically as seen here:
sqlite3 *db;
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"KeyCrypt.sqlite"];
if (sqlite3_open([defaultDBPath UTF8String],&db)==SQLITE_OK) {
NSLog (@"Running keying.");
sqlite3_key(db, "1234", 4);
if (sqlite3_exec(db, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
// password is correct, or, database has been initialized
NSLog (@"This has occured correctly?");
}
else
{
// incorrect password!
NSLog (@"This has occured incorrectly?");
}
}
Am i doing something wrong, somewhere? I've tried researching online for one whole day and couldn't come close to finding a solution for why my database isn't encrypted before or during runtime :(
If you require any extra information i am willing to provide it to you, please help a student out!
THANK YOU!
EDIT:
Excerpt of method used to key my db.
//Initializing the sqlite3_key function.
int sqlite3_key(sqlite3 *db, const void *pKey, int nKey);
sqlite3_key(db, "1234", 4);
Apparently i didn't initialize the sqlite3_key -_-". Also eventhough the file is encrypted the check still says something occurred incorrectly and database wasn't successfully opened.
Regarding the opening of databases, every instance i open my database i have to run the sqlite3_key right? And during that instance I can access the database as per normal right?
Thank you for all the help.