SQLCipherを使用してデータベースの暗号化されたコピーを作成できるようになりました。現在、それをプロジェクトに統合しようとしています。アプリデリゲートで次のコードを使用して、データベースの暗号化を解除しようとしました...
NSString *databasePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
stringByAppendingPathComponent: @"encrypted.db"];
if (sqlite3_open([databasePath UTF8String], &db) == SQLITE_OK) {
const char* key = [@"BIGSecret" UTF8String];
sqlite3_key(db, key, strlen(key));
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(@"correct password");
} else {
// incorrect password!
NSLog(@"incorrect password");
}
その後、永続ストアで、次のコードを使用します。
if (__persistentStoreCoordinator != nil) {
return __persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"encrypted.db"];
NSError *error = nil;
__persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
データベースの作成後に初めてプログラムをロードすると、「正しいパスワード」ログが取得されますが、その後はいつでも「不正なパスワード」が取得されますが、データベースは引き続き使用可能であるため、データベースはデータベースであると信じられます。上書きされているか何かです。