Trying to encrypt an NSDictionary when writing to file

I'm currently saving an NSDictionary to file on the iOS device. However, NSDictionary files are readable XML. I don't want people to be able to get in and read the contents so I need to be able to encrypt the file on writing and decrypt when loading it back again.

I'm currently saving the file like this:

NSFileManager* fileManager = [NSFileManager defaultManager];
if (!fileManager)
{
    NSLog(@"Failed to get file manager to save.");
    return;
}

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* filePath = [documentsDirectory stringByAppendingPathComponent:@"save.dic"];
[m_dictionary writeToFile:filePath atomically:YES];

And I'm loading the dictionary like this:

NSArray*  paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* filePath = [documentsDirectory stringByAppendingPathComponent:@"save.dic"];
m_dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

Can anyone tell me a nice way of encrypting\decrypting this?

Cheers, Rich

21
задан Rich Brooks 5 May 2011 в 10:05
поделиться