@tcoyle Thanks for providing the sample. I have run it on this side. In this example, I believe the problem is that you are constructing the database path in two different ways. In
createDatabase you do the following:
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:[databaseName stringByAppendingString:@".db"]];
which results in a database path like this
However, later in
openDatabase the path is constructed like this (note the omission of the trailing.db):
NSString *path = [documentsDirectory stringByAppendingPathComponent:dbName];
This results in an entirely different database path
sqlite3_key operation used in
verifyKey is actually operating on a database file that doesn’t exist, and thus the prepare statement succeeds (it is essentially creating the file from scratch using that key).
When the reference code is corrected to normalize the way that the database paths are constructed (i.e. so that the
openDatabase is operating on the same encrypted database file created by
verifyKey method returns false when passed an incorrect key.
This was verified on a device running the latest iOS 10 seed, compiled using the latest XCode 8.
Can you please look through your application code and determine if this same logical error is also affecting your application?