It seems you are using this piece of code
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc( bufferSize );
size_t numBytesEncrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt( kCCEncrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
tempkey, kCCKeySizeAES256,
(void*)IV /* initialization vector (optional) */,
input_raw_data, data_length, /* input */
buffer, bufferSize, /* output */
&numBytesEncrypted );
I've also gone through the same problem and I found the solution which is do not use the above function it will add extra bytes in encrypting. Just use the two functions instead of this one. Here is my solution
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc( bufferSize );
size_t numBytesEncrypted = 0;
CCCryptorRef ccRef;
CCCryptorCreate(kCCEncrypt, kCCAlgorithmAES128, 0, tempkey, kCCKeySizeAES256, IV, &ccRef);
CCCryptorStatus cryptStatus = CCCryptorUpdate(ccRef, input_raw_data, data_length, buffer, bufferSize, &numBytesEncrypted);
CCCryptorRelease(ccRef);
if( cryptStatus == kCCSuccess )
{
//the returned NSData takes ownership of the buffer and will free it on deallocation
return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
}