我正在尝试解密用 Java 加密的 ios 中的数据。以下是代码:
+(NSString*) decryptData:(NSString*) data:( NSData*) passKey {
NSString * strKey = [Base64Util encodeBase64WithData:passKey];
NSLog( @" decryption key: %@" ,strKey);
//decrypt `data
NSData * nsData = [Base64Util decodeBase64WithString:data];
NSLog(@"here 1: %@",nsData);
size_t numOfBytesDecrypted;
size_t bufferSize = nsData.length + kCCBlockSizeAES128;
NSMutableData * buffer = [NSMutableData dataWithLength:bufferSize];
CCCrypt(kCCDecrypt, kCCKeySizeAES128, kCCOptionECBMode , derivedKey.bytes, derivedKey.length, Nil , passCodeData.bytes, passCodeData.length, buffer. mutableBytes, bufferSize, &numOfBytesDecrypted);
return [NSData dataWithBytesNoCopy:buffer. mutableBytes length :numOfBytesDecrypted];
}
但是当 CCCrypt 函数执行时,它会抛出一个 EXC_BAD_ACCESS 代码 2。我启用了 ARC。我无法找到错误的原因。帮助将不胜感激。