I am having an issue with EncryptedStore SQLCipher wrapper to encrypt core data.
I've added C-flags for this as:
Debug = -DSQLITE_HAS_CODEC -DSQLITE_TEMP_STORE=2 -DSQLITE_THREADSAFE -DSQLCIPHER_CRYPTO_CC
Release = -DSQLITE_HAS_CODEC -DNDEBUG -DSQLITE_OS_UNIX=1 -DSQLITE_TEMP_STORE=2 -DSQLITE_THREADSAFE -DSQLCIPHER_CRYPTO_CC
And used it as:
func encryptedCoordinator() -> NSPersistentStoreCoordinator {
var coordinator:NSPersistentStoreCoordinator?
let ops:[String : Any] = [NSMigratePersistentStoresAutomaticallyOption:(true), NSInferMappingModelAutomaticallyOption:(true), EncryptedStorePassphraseKey:sqlCipherKey, EncryptedStoreDatabaseLocation:self.sqliteFileURL()]
do {
coordinator = try EncryptedStore.make(options: ops, managedObjectModel: self.managedObjectModel, error: ())
}catch {
fatalError("Error opening encrypted DB: \(error)")
}
return coordinator!
}
It is working fine in XCode8, but it's giving error in XCode9-beta.
Error line:
- (BOOL)changeDatabasePassphrase:(NSString *)passphrase error:(NSError *__autoreleasing*)error {
BOOL result;
int status;
if ([passphrase length] > 0) {
// Password provided, use it to key the DB
const char *string = [passphrase UTF8String];
status = sqlite3_rekey(database, string, (int)strlen(string));//ERROR line
string = NULL;
passphrase = nil;
} else {
// No password
status = SQLITE_OK;
}
result = status == SQLITE_OK;
if (result) {
result = [self checkDatabaseStatusWithError:error];
}
return result && (*error == nil);
}
Function is declared in EncryptedStroe/sqlite3.h as:
SQLITE_API int sqlite3_rekey(
sqlite3 *db, /* Database to be rekeyed */
const void *pKey, int nKey /* The new key */
);
SQLITE_API int sqlite3_rekey_v2(
sqlite3 *db, /* Database to be rekeyed */
const char *zDbName, /* Name of the database */
const void *pKey, int nKey /* The new key */
);
I think the problem is the import EncryptedStore.m file does:
#import <sqlite3.h>
It uses <> so the system sqlite library is imported, which doesn't include these functions. By changing <> with "" everything compiles fine.
Found another solution here.
Mainly changing the Header Search Paths.
Try changing it from $(PROJECT_DIR)/sqlcipher/src
to $(PROJECT_DIR)/sqlcipher
(i.e. remove the /src from the path)." Did the trick for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With