我正在加密像图像文件这样的大文件(可能有任何大小 - 从一些 KB 到大 MB)。我正在使用以下代码进行加密,这在 iPhone Simulator 5.1 上运行良好:
+ (NSData *)encryptedDataForData:(NSData *)data key:(NSData *)key error:(NSError **)error {
   size_t outLength;
   NSMutableData * cipherData = [NSMutableData dataWithLength:data.length + kCCBlockSizeAES128];
   CCCryptorStatus result = CCCrypt(kCCEncrypt,
                 kCCAlgorithmAES128, 
                 kCCOptionPKCS7Padding, 
                 key.bytes, 
                 key.length, 
                 NULL,
                 data.bytes, 
                 data.length, 
                 cipherData.mutableBytes,
                 cipherData.length, 
                 &outLength); 
   if (result == kCCSuccess) {
       cipherData.length = outLength;
   } 
   else {
    NSLog(@"errorcode: %d", result);
    return nil;
}
   return cipherData;
}
但是,当我使用相同的代码加密设备上的某些图像时 - iPhone 5.1.1,
这种加密给了我一个 kCCaramError (-4300)。我在模拟器中有相同的值 - 但它在那里工作正常。请问有什么帮助吗?