Trying to encrypt an NSDictionary when writing to file

前端 未结 1 1058
花落未央
花落未央 2021-01-30 18:09

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

相关标签:
1条回答
  • 2021-01-30 18:59

    Use a NSKeyedArchiver to create an NSData object from your dictionary (NSKeyedArchiver archivedDataWithRootObject:). Then encrypt the NSData with AES and write that to your file.

    Reading takes the reverse: first, read the NSData, decrypt it via the method from the mentioned link, then pass the decrypted NSData to NSKeyedUnarchiver (NSKeyedUnarchiver unarchiveObjectWithData:) and you get your dictionary back.

    0 讨论(0)
提交回复
热议问题