如何将输出保存system("openssl enc -aes-128-cbc -k secret -P -md sha1 > FILENAME")
到文件中。
我尝试了以下方法:
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"%@/textfile.txt",
documentsDirectory];
NSString *str=[NSString stringWithFormat:@"openssl enc -aes-128-cbc -k secret -P -md sha1 > %s",[fileName UTF8String]];
NSLog(@"AES Key is %@",str);
system([str UTF8String]);
NSString *strAES = [NSString stringWithContentsOfFile:fileName encoding:nil error:nil];
NSLog(@"strAES Key is %@",strAES);
NSString *strAESKey=[[[[strAES componentsSeparatedByString:@"\n"] objectAtIndex:1] componentsSeparatedByString:@"="] objectAtIndex:1];
NSLog(@"strAESKey Key is %@",strAESKey);
// NSString *content = @"One\nTwo\nThree\nFour\nFive";
[str writeToFile:fileName atomically:NO encoding:NSStringEncodingConversionAllowLossy error:nil];`
我哪里错了?
该system()
函数将输出发送到控制台,但由于 iPhone 没有控制台,我需要将输出重定向到文本文件并从文件中获取密钥以将其用于加密/解密。