title: AES128 decryption with NSData as key
body: <p>I'm having a hard time decrypting <code>NSData</code> with <code>NSData key</code>. While decrypting with <code>NSString</code> everything works fine, yet with data as key, the method returns null <code>NSData</code>, eventhough status is ok, and key is also correct for that data. Here is my call</p>
  
  <pre><code>NSData *decrypted = [AES AES128DecryptWithKey:data key:mute];
  NSLog(@"DECRYPTED &gt;&gt; %@", decrypted);
  </code></pre>
  
  <p>And my method</p>
  
  <pre><code>+ (NSData*)AES128DecryptWithKey:(NSData*) data key:(NSData*)key {
  
      NSUInteger dataLength = [data length];
      NSLog(@"trying to decrypt &gt;&gt; %@ with key &gt;&gt; %@", data, key );
  
      size_t bufferSize           = dataLength + kCCBlockSizeAES128;
      void* buffer                = malloc(bufferSize);
  
      size_t numBytesDecrypted    = 0;
      CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
                                            [key bytes], kCCKeySizeAES128,
                                            NULL /* initialization vector (optional) */,
                                            [data bytes], dataLength, /* input */
                                            buffer, bufferSize, /* output */
                                            &amp;numBytesDecrypted);
      NSLog(@"cryptstatus %d", cryptStatus);
      if (cryptStatus == kCCSuccess)
      {
          return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
      }
  
      free(buffer); //free the buffer;
      return nil;
  }
  </code></pre>
  
  <p>NSLog output:</p>
  
  <pre><code>trying to decrypt &gt;&gt; &lt;152f052e 79436003 7a9c1a59 3b82f1c4&gt;
  with key &gt;&gt; &lt;1b510e76 ac0000a1 027af26a e25ad24a&gt;
  cryptstatus 0
  DECRYPTED &gt;&gt; &lt;&gt;
  </code></pre>
  
  <p>Looked into <code>RNEncryptor</code>, yet it only has aes256, while i need 128. Any ideas?</p>