Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Encryption is a decent method of scrambling the data but i don't know how to implement encription concept.
- NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
- NSArray *arrData = [[NSArray alloc]initWithContentsOfFile:filePath];
- NSData *datas = [NSKeyedArchiver archivedDataWithRootObject:arrData];
- [datas writeToFile:filePath atomically:YES];
- @implementation TestViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- NSString *path = [[NSBundle mainBundle] pathForResource:@"Encryption-Test" ofType:@"enc"];
- NSData *passEncryptedData =[[NSData alloc] initWithContentsOfFile:path];
- NSString *pass = @"asdasd";
- NSData *dataDecrypted = [RNOpenSSLDecryptor decryptData:passEncryptedData withSettings:kRNCryptorAES256Settings password:pass error:nil];
- id plist = [NSPropertyListSerialization propertyListFromData:dataDecrypted mutabilityOption:NSPropertyListImmutable format:nil errorDescription:nil];
- assert(plist);
- self.text.text = [plist description];
- }
- @end
- NSString *txtPath = [documentsDirectory stringByAppendingPathComponent:@"questions.enc"];
- if ([fileManager fileExistsAtPath:txtPath] == NO) {
- NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"questions" ofType:@"enc"];
- [fileManager copyItemAtPath:resourcePath toPath:txtPath error:&error];
- }
- NSString *filePath1 = [documentsDirectory stringByAppendingPathComponent:@"questions.encr"];
- NSData *passEncryptedData =[[NSData alloc] initWithContentsOfFile:filePath1] ;
- NSString *pass = @"asdf"; // Insert your password from step 1
- NSData *dataDecrypted = [RNOpenSSLDecryptor decryptData:passEncryptedData withSettings:kRNCryptorAES256Settings password:pass error:&error];
- NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"questionsDECRYPTED.plist"]; //The Decrypted file saved here
- [dataDecrypted writeToFile:appFile atomically:YES];
- NSString *txtPath = [documentsDirectory stringByAppendingPathComponent:@"questions.enc"];
- if ([fileManager fileExistsAtPath:txtPath] == NO) {
- NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"questions" ofType:@"enc"];
- [fileManager copyItemAtPath:resourcePath toPath:txtPath error:&error];
- }
- NSString *filePath1 = [documentsDirectory stringByAppendingPathComponent:@"questions.encr"];
- NSData *passEncryptedData =[[NSData alloc] initWithContentsOfFile:filePath1] ;
- NSString *pass = @"asdf"; // Insert your password from step 1
- NSData *dataDecrypted = [RNOpenSSLDecryptor decryptData:passEncryptedData withSettings:kRNCryptorAES256Settings password:pass error:&error];
- NSString *appFile = [documentsDirectory stringByAppendingPathComponent:@"questionsDECRYPTED.plist"]; //The Decrypted file saved here
- [dataDecrypted writeToFile:appFile atomically:YES];
- NSDictionary *Your_NSDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
- @"Obj1", @"Key1",
- @"Obj2", @"Key2", nil];
- //store dictionary
- NSMutableData *yourData = [[NSMutableData alloc] init];
- NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
- [archiver encodeObject:Your_NSDictionary forKey: @"key"];
- [archiver finishEncoding];
- [yourData writeToFile:@"FilePath" atomically:YES];
- NSString* filePath = [[NSBundle mainBundle] pathForResource:@"Data"
- ofType:@"plist"];
- NSDictionary* data = [NSDictionary dictionaryWithContentsOfFile:filePath];
- NSMutableDictionary * rootObject;
- rootObject = [NSMutableDictionary dictionary];
- [rootObject setValue: data forKey:@"accounts"];
- [NSKeyedArchiver archiveRootObject: rootObject toFile: path];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement