I hear that we can encrypt documents converting them to NSData and using the WriteToFile method to write to the directory for that I realized the following test:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:@"confidencial"];
NSString *content = @"This message is confidential password number is xxxxxxxxxxxx!";
NSData *data = [content dataUsingEncoding:NSUTF8StringEncoding];
[data writeToFile:fileName options:NSDataWritingFileProtectionComplete error:nil];
The file was saved in my document directory, well the documentation says that the command NSDataWritingFileProtectionComplete:
Any file with this setting is protected ten seconds after the device is locked. This is the highest level of protection. Files with this setting may not be available when your program is running in the background. When the device is unlocked, these files are unprotected.
To check if is true, I lock my device (simulator) go to my document directory and open the file and for my surprise I can read the message:
This message is confidential password number is xxxxxxxxxxxx!
Why is not encrypted?
You used NSData to encode the string. Encoding is not encryption. There's a difference. If you want true encryption then you'll have to look into using the cryptography services of OSX.
However if you just want to make the string not easy to read (obscure it) then you can do something like this when converting to NSData. Note that this is not secure at all though.
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:content];
And when you want to read that data back into your application you read the file back as a data object and then convert the data object back into NSString as follows:
NSString *content = [NSKeyedUnarchiver unarchiveObjectWithData:data];
This is not encryption but it should obscure the string making it hard for someone to read it from the saved file.