我正在加密像图像文件这样的大文件(可能有任何大小——从 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,
这个加密给我一个 kCCParamError (-4300)。我在模拟器中有相同的值 - 但它在那里工作正常。 有什么帮助吗?
最佳答案
我用错了 key 。
我的 key 由 42 个字符组成。
相反,它应该有 24 个字符。 (使用 key = 123456789012345678901234 有效)。
关于iphone - 设备上的 iPhone kccparamerror 中的 AES 加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12406010/