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.
Using the code at 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:
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:
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
Here’s a very simple answer to this, hope this simplifies the problem, if any;
First of you need to download the NSData+AES files for here. You just need the NSData+AES.h & NSData+AES.m along with cipher.h & cipher.m files. Once in custody, add the files to your Xcode project and remove #import Cocoa/Cocoa.h> header from NSData+AES.h and cipher.h (only for those who intend to program for iOS, if for MacOS please let the header be). Import NSData+AES.h in your file where you fetch and write your plist file.
Now that the initial basics have been laid down, we take on the usage of these important files. What you need to understand is that the way you want to decrypt and encrypt your data. At the first run you need to copy your plist to the documents folder and then encrypt it. Note, if you copy it and try to decrypt it straight it will throw and exception, so to cater that, we’ll use a UserDefaults Boolean value and skip the decryption on the first run. Also you need to define a preprocessor directive constant string to entertain the secret key for encryption and decryption. Here’s what you’ll have in your DataHandler class;
But the first time the dataDictionary_ is populated, we have to force ably persist it in AppDelegate.m in didFinishLaunching:
The data will always be encrypted at all times but in the copyPlist method you will populate your models with respect to the dataDictionary_ and interact with those models. When done, you'll persist your models and encrypt again hence no errors will occur. It's simple and a pretty workable solution without any hassle. Cheers.
The link provided by howanghk contains code with a bug. Apply fix provided by InoriXu on that webpage to resolve the issue. You have to modify both encrypt and decrypt functions.
So after a line:
add:
And change line:
into:
The code itself still adds some space padding behind, but if you need it to encrypt a property list, you'll be fine.