title: AES decryption in iOS: PKCS5 padding and CBC
body: <p>I am implementing for iOS some decryption code for a message originating on a server over which I have no control.  A previous implementation on another platform documents the decryption requirements AES256, specifies the key and the initialization vector, and also says:</p>
  
  <pre><code> * Cipher Mode: CBC
   * Padding: PKCS5Padding
  </code></pre>
  
  <p>The options for creation of a CCCryptor object include only kCCOptionPKCS7Padding and kCCOptionECBMode, noting that CBC is the default.  From what what I understand about padding for encryption, I don't understand how one might use both; I thought they were mutually exclusive.   In creating a CCCryptor for the decryption, I have tried using both a 0 for options and kCCOptionPKCS7Padding, but both give me gibberish after decryption.</p>
  
  <p>I have compared the dump of this decryption with a dump of the decoded byte buffer on the other platform and confirmed that they really are different.  So there is something that I am doing different in this implementation that is significantly different, I just don't know what... And don't have a clue as to how to get a handle on it.  The platforms are different enough that it is difficult to infer much from the previous implementation because it is based on a very different platform.  And of course, the author of the previous implementation has since departed.</p>
  
  <p>Any guesses what else could be incompatible or how to troubleshoot this thing?</p>