title: AES128 encryption giving different results in iOS 6 & iOS 7
body: <p>Well, I'm working on an app that sends and receives encrypted data from a web server.
  The issue here, is that, my encryption results were different.
  Now, comparing the result running on iOS6 &amp; iOS 7 simulator, I noticed the hex was different too, and I didn't touch the code.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>@implementation NSData (AES_128)
  - (NSData *)AES128Encrypt {
  // 'key' should be 32 bytes for AES256, will be null-padded otherwise
  char keyPtr[kCCKeySizeAES128+1]; // room for terminator (unused)
  bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
  
  // fetch key data
  [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
  
  NSUInteger dataLength = [self length];
  
  //See the doc: For block ciphers, the output size will always be less than or
  //equal to the input size plus the size of one block.
  //That's why we need to add the size of one block here
  size_t bufferSize = dataLength + kCCBlockSizeAES128;
  void *buffer = malloc(bufferSize);
  
  size_t numBytesEncrypted = 0;
  
  char ivPtr[kCCBlockSizeAES128];
  
  bzero(ivPtr, sizeof(ivPtr));
  
  [iv getCString:ivPtr maxLength:sizeof(ivPtr) encoding:NSUTF8StringEncoding];
  
  CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
                                        keyPtr, kCCKeySizeAES128,
                                        ivPtr /* initialization vector (optional) */,
                                        [self bytes], dataLength, /* input */
                                        buffer, bufferSize, /* output */
                                        &amp;numBytesEncrypted);
  if (cryptStatus == kCCSuccess) {
      //the returned NSData takes ownership of the buffer and will free it on deallocation
      return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
  }
  
  free(buffer); //free the buffer;
  return nil;
  }
  </code></pre>
  
  <p>The key and the iv are static, 16 bytes char arrays.
  What am I missing here? Thanks in advance</p>