title: AES encryption algorithm not decrypting for few document formats
body: <p>I am trying to decrypt the documents using AES encryption algorithm.</p>
  
  <p>I am getting key from enc file and using it in the algorithm. </p>
  
  <p>When I am trying to decrypt the documents, I am not able to decrypt few format of documents such as <code>docx, xlsx, pptx and txt</code> files. Please find my code below.</p>
  
  <pre><code>- (NSData *)AES256Decrypt
  {
  
  NSString* path = [[NSBundle mainBundle] pathForResource:&lt;filename&gt; ofType:@"enc"];
  
  // fetch key data from the key file
  NSData *keyData = [NSData dataWithContentsOfFile:path];
  
  NSUInteger dataLength = [self length];
  
  size_t bufferSize = dataLength + kCCBlockSizeAES128;
  void *buffer = malloc(bufferSize);
  
  size_t numBytesDecrypted = 0;
  CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionECBMode,
                                        [keyData bytes], kCCKeySizeAES256,
                                        NULL
                                        [self bytes], dataLength, /* input */
                                        buffer, bufferSize, /* output */
                                        &amp;numBytesDecrypted);
  
  if (cryptStatus == kCCSuccess)
  {
      return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
  }
  
  free(buffer);
  return nil;
  }
  </code></pre>
  
  <p>I added the above method as category for NSData.</p>
  
  <p>I tried to encrypt and decrypt in client side. Even that document is not able to decrypt properly. When I tried to open decrypted file, I am getting <code>office open xml word processing document</code> error when using QLPreviewController to view the document.</p>
  
  <p>I am not able to find why this happening for few documents alone. Can anyone help me to fix this issue.
  Thanks</p>