Secure contents in Documents directory
Use:
- (BOOL)writeToFile:(NSString *)path options:(NSDataWritingOptions)mask error:(NSError **)errorPtr
with one of the file protection options:
NSDataWritingFileProtectionComplete (iOS 4.0)
NSDataWritingFileProtectionCompleteUnlessOpen (iOS 5.0)
NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication (iOS 5.0)
See: Apple Documentation
NSDataWritingFileProtectionComplete
In this case, the file is stored in an encrypted
format and may be read from or written to only while the device is
unlocked. At all other times, attempts to read and write the file
result in failure.
Note: Doing your own encryption raises the problem of key storage and the best answer there is to use the Keychain. Key handling is the biggest problem and the NSData methods handle that.
Is the PathProvider documents directory a secure location?
Yes, NSDocumentDirectory on iOS and AppData on Android are secure locations.
This line from the example gives you the correct path for storing files which can only be accessed by your app:
String dir = (await PathProvider.getApplicationDocumentsDirectory()).path;
On Android dir
resolves/data/data/com.yourcompany.AppName/
. On iOS devices the folder is /var/mobile/Containers/Data/APP_ID/Documents
.
Check the Android Security Tips , the section on Internal Storage:
By default, files that you create on internal storage are accessible
only to your app. Android implements this protection, and it's
sufficient for most applications.
The exception here is that when your app runs on a rooted Android device, the app data folder is not secure any more, see https://stackoverflow.com/a/8184699.
Related Topics
How to Encrypt and Decrypt a String(Plain Text) with Rsa Public Key in iOS, Swift
iPhone Only App Rejected for Not Running on iPad
Changing Iphone's Date and Time
Sprite Kit Set Min. and Max. for Jump
Getting the Action of Uigesturerecognizer in iOS
iOS Facebook Sdk 3.1 Retrieve Friend Birthday Returning Null
Uialertcontroller Set Attributed Messages
Recording from Remoteio: Resulting .Caf Is Pitch Shifted Slower + Distorted
How to Overlay One Video on Another in iOS
Ios: Production Push Notifications, Invalid Token from Apns Server
Error Using Swift - Instance Member Cannot Be Used on Type 'Viewcontroller'
How to Record a Video with Augmented Reality
Executefetchrequest Throw Fatal Error: Nsarray Element Failed to Match the Swift Array Element Type
Does Swift Not Work with Function Pointers
How to Make Skscene Have Fixed Width
How to Get All Nsrange of a Particular Character in a Nsstring