How to Encrypt, Decrypt and Delete a plist file

限于喜欢 提交于 2019-12-08 09:40:01

问题


I am making a password app that stores user logins/password etc for credit card, bank info etc into a plist file. I have googled and I know how to encrypt and decrypt a string using AES encryption with key. I got that to work for simple login and password. I encrypt and save the login and password to NSdata and then decrypt and read it

- (NSData *)AES256EncryptWithKey:(NSString *)key;
- (NSData *)AES256DecryptWithKey:(NSString *)key;


- (NSData*) encryptString:(NSString*)plaintext withKey:(NSString*)key;
- (NSString*) decryptData:(NSData*)ciphertext withKey:(NSString*)key;

What I want to do is when the user exits my app by pushing the home button, I want to encrypt the password.plist file save it as an encrypted datafile and then delete the readable password.plist xml file from his iPhone. (password.plist file will have multiple rows, values e.g. credit card1 info, credit card2 info etc)

When the user logs back in I want to decrypt and recreate password.plist file. Anyone know how this can be done?


回答1:


  • you could use Keychain Services to encrypt the password for you.
  • you could use NSFileProtectionComplete to encrypt your plist file for you.

It's always best to rely on someone else having implemented an encryption protocol properly, before you try to create your own protocol (for example, where in your system would the integrity of the encrypted data be ensured?). Apple have already done a pretty good job in this regard, so just use their stuff.



来源:https://stackoverflow.com/questions/8694885/how-to-encrypt-decrypt-and-delete-a-plist-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!