Friday, October 26, 2018

iOS encrypting App's files

We can specify the level of data protection that you want to apply on each of the files. There are four levels available, each of which determines when you one may access the file. If one do not specify a protection level when creating a file, iOS applies the default protection level automatically.

    No protection. The file is always accessible.

    Complete until first user authentication. (Default) The file is inaccessible until the first time the user unlocks the device. After the first unlocking of the device, the file remains accessible until the device shuts down or reboots.

    Complete unless open. You can open existing files only when the device is unlocked. If you have a file already open, you may continue to access that file even after the user locks the device. You can also create new files and access them while the device is locked or unlocked.

    Complete. The file is accessible only when the device is unlocked.

Below is how to encrypt

Do {
   Try data.write(to:fileURL, options:.completeFileProtection);
}
Catch {
// handle errors.
}

References:
https://developer.apple.com/documentation/uikit/core_app/protecting_the_user_s_privacy/encrypting_your_app_s_files

No comments:

Post a Comment