7

Question

How can I ensure data is encrypted when using NSData.writeToFile:options:error: with the NSDataWritingFileProtectionComplete?

Background research: Enabling data encyption

According to Apple documentation:

Data protection is available on most iOS devices and is subject to the following requirements:

  • The file system on the user’s device must support data protection. This is true for newer devices, but for some earlier devices, the user might have to reformat the device’s disk and restore any content from a backup.

  • The user must have an active passcode lock set for the device.

https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW11

The requirements state that user must activate passcode lock for the device, this is reinforced by the following end user documentation:

Enable data protection by configuring a passcode for your device:

  1. Tap Settings > General > Passcode.
  2. Follow the prompts to create a passcode.
  3. After the passcode is set, scroll down to the bottom of the screen and verify that the text "Data protection is enabled" is visible.

Passcode lock screen

http://support.apple.com/kb/HT4175

Similar SO Questions:

How can I find out if the iPhone user currently has a passcode set and encryption enabled? seems like the answer to this question is no longer valid.

Community
  • 1
  • 1
Edward Wilde
  • 25,967
  • 8
  • 55
  • 64
  • Why do you want to do this? – Billy ONeal Apr 22 '13 at 03:48
  • I want to ensure that data is encrypted on the device. My understanding is that if the passcode is not set, encryption is not possible. – Edward Wilde Apr 22 '13 at 11:13
  • Why do you want to ensure data is encrypted on the device? Without a pass code of some sort, the key has to also be stored on the device. Which would defeat the purpose. – Billy ONeal Apr 22 '13 at 16:23
  • 1. I want to ensure data is encrypted, the application will store sensitive medical information, that has to be kept locally on the device. If that means the user has to set a passcode then, 2. How do I ensure the user has set a passcode? Currently as far as I can tell the only valid solution seems to be implementing your own application login and encrypting yourself using something like sqlcipher.net. However for completion want to see if there is an option were I can stay inside the Apple framework. – Edward Wilde Apr 23 '13 at 08:30
  • Just encrypting the data and storing the key right next to it doesn't buy you anything. http://blogs.msdn.com/b/ericlippert/archive/2011/09/27/keep-it-secret-keep-it-safe.aspx "That is, modern crypto is essentially a form of mechanical advantage. With a gearing system or a lever you can turn a small motion into a large motion. With a strong cryptosystem you can turn the security of a 1 KB key file into the security of a 10 MB data file. Cryptosystems do not manufacture new security, any more than a lever manufactures new motion." You need that initial secret. – Billy ONeal Apr 23 '13 at 19:32
  • It will be better to have an application specifc passcode and use it genearate a key(incorporating some device parameters,salt -PBKDF2) and use it to encrypt application data. – xrcsblue Sep 13 '13 at 09:58
  • @Edward, did you find a solution to this problem? – T.J. Feb 08 '14 at 15:21
  • @T.J. Yes I implemented my own security and had the user enter a pin on application launch. I used sqlcipher (http://sqlcipher.net/) to encrypt the application data and Pincode (https://github.com/ewilde/Pincode) to get the pin from the user (which is based on https://github.com/christo16/CPLockController). – Edward Wilde Feb 09 '14 at 12:22
  • Kudos @EdwardWilde I'm looking for a similar solution! – Matthys Du Toit Jul 08 '14 at 13:22

1 Answers1

1

The requirements state that user must activate passcode lock for the device, this is reinforced by the following end user documentation.

If user doesn't have any passcode enabled the encryption would be useless. The unwanted user can use the app directly then anyway.


A solution for your problem would be to manually implement encryption for app data and use a app specific password which you ask the user on every app launch.

I've seen that system at an online banking software for iOS, but I wouldn't recommend that system since it is very annoying for the user.

miho
  • 11,765
  • 7
  • 42
  • 85