Data Protection and Encryption
Protect files and use CryptoKit basics.
Data Protection on iOS
iOS encrypts files on disk by default, but you can choose when a file's contents are decryptable using Data Protection classes. These tie file access to the device lock state, much like Keychain accessibility classes do for secrets.
import Foundation
// File-level protection ties decryption to lock state.
// Set a protection class when writing sensitive files.The Protection Classes
The main file protection levels are .complete (unreadable while locked), .completeUnlessOpen (stays readable if already open when locked), .completeUntilFirstUserAuthentication (readable after first unlock), and .none.
import Foundation
// FileProtectionType:
// .complete
// .completeUnlessOpen
// .completeUntilFirstUserAuthentication (default)
// .none
let level = FileProtectionType.complete
_ = levelAll lessons in this course
- Storing Secrets in the Keychain
- Keychain Access Control
- Biometric Authentication
- Data Protection and Encryption