Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypt/decrypt .plist file ios

i have a plist with some stored data and want to encrypt decrypt so it's not readable using objective c. i've read about AES encryption etc but i want the whole plist to be encrypted some how not the strings in the plist....

any help will be really appreciated.

like image 708
fizampou Avatar asked Dec 12 '12 15:12

fizampou


1 Answers

Using the code at https://web.archive.org/web/20150612123348/http://blog.objectgraph.com/index.php/2010/04/20/encrypting-decrypting-base64-encode-decode-in-iphone-objective-c/ (the link that you provided in comment), you can encrypt your plist by:

NSData *plistFileData = [NSData dataWithContentsOfFile:plistPath];
NSData *encryptedData = [plistFileData AESEncryptWithPassphrase:password];
[encryptedData writeToFile:encryptedPath atomically:YES];

plistPath is a NSString containing the path to the plist file you want to encrypt
password is the encryption key you would like to use
encryptedPath is where you want to save the encrypted file

to decrypt:

NSData *encryptedData = [NSData dataWithContentsOfFile:encryptedPath];
NSData *plistFileData = [plistFileData AESDecryptWithPassphrase:password];
[plistFileData writeToFile:plistPath atomically:YES];

encryptedPath is a NSString containing the path to the encrypted plist file
password is the encryption key you would like to use
plistPath is where you want to save the decrypted plist file

like image 74
howanghk Avatar answered Nov 06 '22 01:11

howanghk