nielsmouthaan / SecureNSUserDefaults

NSUserDefaults category for iOS and Mac OS X with additional methods to securely save data using strong AES 256-bit encryption.
MIT License
179 stars 26 forks source link

Return nil if existing `objectForKey:` is not an NSData object #6

Closed leslie-lei closed 8 years ago

leslie-lei commented 8 years ago

During migration phase, we have an issue where the user does a partial update of the app, and we start reading from the old NSUserDefaults plist before we can update its values to the encrypted version. This causes a crash on line 137 CocoaSecurityResult *result = [CocoaSecurity aesDecryptWithData:data key:aesKey iv:aesIv]; where the data object is actually an NSString (other other object types) underneath.

Updating to verify data is of class NSData before passing it down for decryption.

leslie-lei commented 8 years ago

Never mind, it was only an exception breakpoint. Existing code already catches the exception and return nil.