使用以下功能进行加密: https://gist.github.com/Veelian/7541502
每当我读取二进制文件并对其应用加密时, 我得到了该文件的一些加密文本,但每当我执行时 再次上面的操作,然后我会得到不同的加密文本 文件同样的文件内容也一样,仍然得到不同的加密文本 如果再次执行相同的操作。
请找到以下代码
NSString *filePath = @"/Users/xyx/Desktop/NOTICE.txt";
const char *cfilePath = [filePath cStringUsingEncoding:NSASCIIStringEncoding];
FILE *fileStream= fopen (cfilePath,"rb");
NSDictionary *properties = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
NSNumber *fileSize = [properties objectForKey: NSFileSize];
long l_fileSize = [fileSize longValue];
temp = (char*) malloc (sizeof(char)*l_fileSize);
fgetpos(fileStream,&pos);
int bytesToRead = (int)l_fileSize;
size_t byt=fread(temp,1,bytesToRead,fileStream);
buffer = [NSData dataWithBytes:(const void *)temp length:sizeof(char)*byt];
NSLog(@"Buffer : %@",buffer);
BytesRead = buffer.length;
NSData *encryptedBytes=[buffer AES256EncryptWithKey:[Security key]]; //taking key from other class
size_t length = [encryptedBytes length] + 1;
unsigned char aBuffer[length];
[encryptedBytes getBytes:aBuffer length:length];
NSString *encBytes = [NSString stringWithFormat:@"%s", aBuffer];
NSLog(@"ENcrypted Bytes : %@",encBytes);