I’ve have a .txt file containing an NSString (encrypted using a private key) that my application uses (decrypted using a public key). Everything works beautifully for one string, however, if I have another NSString that I want to use I have to create another separate .txt file with that encrypted NSString. I know there has to be a way to put all the NSStrings in one file and somehow parse it, although I’m not sure how to achieve this. Could it be done using a .plist file that contains all the encrypted strings?
This is an example of the code I use to decrypt my .txt file with one NSString:
NSString *filePath = @"/path/to/file.txt";
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
crypto = [[MyCrypto alloc] initWithPublicKey:publicKeyData privateKey:privateKeyData];
NSError *err;
theString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&err];
if (!theString) {
NSLog(@"error: %@", err);
}
[crypto setClearTextWithString:theString];
decryptedTextData = [crypto decrypt];
NSLog(@"Decrypted: %@", theString);
...
If someone can shed some light on the subject with an example I would truly appreciate it.
Make a for loop and put your decription code inside, furthermore modify the line
to the following (assuming
iis the loop variable):Where you created
arrayin the initialization part of your code, using:The specified file also has to be a valid PLIST, an array being its root element. Example:
Hope this helps.