开发者

Saving private data securely on device when user exits application

i want to save stuff like user id and pass word and other stuff like this(properties), i do it until now with plist but i understand that plist can be access fr开发者_Python百科om itunes and stuff like this,so there is any other to save stuff like this?


You should be using Keychain Services.


If you want to store username/password values, it's best to store them in the Keychain. One example of how you can do this can be found at this blog entry.


There's not an easy way to encrypt data specifically when the application exits. If you need everything encrypted on disk at all times, Keychain Services is the only way to go.

However, iOS also supports data protection. If a user has set a password on the device, then an application's files can be encrypted automatically by the device. This is known as "File Protection", and there are various options available. The NSDataWritingFileProtectionComplete option, for example, would cause the files to be fully encrypted unless the device is unlocked. If someone doesn't know the password to the device, they would not be able to access those files at all.

To use this API, create an NSData with the contents of the file you want to write. Then pass the file protection option as follows:

NSData *theData;
NSError *error;
[theData writeToURL:someURL
            options:NSDataWritingFileProtectionComplete
              error:&error];

If you're just saving username/password info, though, you should store the password in the Keychain. The username would be the key by which you retrieve the password, so you'll need to store it elsewhere. You could use file protection as detailed above to add some level of protection to the username, but it's not as secure as the keychain is.


Core data may be a good solution, I don't think anybody can just access core data, not easily anyway.


Here is a tutorial that uses applicationWillTerminate in your App Delegate. It does not use KeyChain Services though, you would need to add that. It is using a plist instead.

http://servin.com/iphone/iPhone-Save-and-Restore-Mini-Course.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜