Have you verified that -subdataWithRange:
does copy the bytes? If it does, you can always use +dataWithBytesNoCopy:length:
, just make sure to handle ownership properly.
EDIT
I'm such a fool. Just do this:
int hdrsize; // this contains the size of the header
NSData *data; // this contains full encrypted data with a header
// this gives me information, stored in the header + some additional stuff
NSDictionary *hdr = [self _headerInfoFromData:data];
// And the decryption part
CCCryptorStatus cryptStatus = CCCrypt(
kCCDecrypt,
MS_SEC_ENC_ALGORITHM,
kCCOptionPKCS7Padding,
[key bytes],
MS_SEC_ENC_KEY_SIZE,
[[hdrdict objectForKey:@"iv"] bytes],
data.bytes + hdrsize,
data.length - hdrsize,
buffer,
bufferSize,