title: Anyone else having trouble with iOS 5 encryption?
body: <p>Have a (rather complex) app that works fine on iOS 4 but fails on iOS 5 with a decryption problem.  It's decrypting a SQLite DB page, and the last 16 bytes do not appear to be properly decrypted.</p>
  <p>Does this ring a bell with anyone?</p>
  <h2>Update</h2>
  <p>I've determined that, when CCCryptorUpdate is given a buffer length of 1008 (1024 - 16) it only decrypts 992 bytes (as reported in the dataOutMoved parameter).  This would be OK if CCCryptorFinal returned the remaining bytes, but it reports zero bytes moved.  However, CCCryptorFinal is reporting a -4304 return code (which is an unhelpful kCCDecodeError).</p>
  <h2>Update 2</h2>
  <p>I've pretty nailed it as an out-and-out bug.  I've compared byte-for-byte the output from encryption and the input to decryption, and compared the keys.  Identical.  But if buffer length is 1008 then decryption always fails, even when the decryptor is given a larger output buffer (it says it needs 1024 in that case).  I assume it works fine for 1024, though I haven't gotten past the first oddball sized buffer to tell.</p>
  <h2>Etc</h2>
  <p>Well, it appears that nothing decrypts.  This is using the &quot;all in one&quot; CCCrypt() interface that removes any chance of an error with the sequencing of CCCryptorCreate/Update/Final.  I wonder if it's a problem with AES128?</p>
  <p>A curious thing is that when page 1 of the DB is encrypted the encryption always reports back 16 bytes more moved than what I tell it -- if I tell it 1008 it reports 1024, if I tell it 1024 it reports 1040.  No other page does that, and I don't see how the CCCrypt could know what page it's processing.  Like I said, curious.</p>
  <h2>Found it (I think)</h2>
  <p>The old code was specifying <code>kCCOptionPKCS7Padding</code>, which, as I understand it, should only be used for encrypting where the buffer length is not a multiple of the block length (and where additional output buffer space is provided).  This caused virtually all decrypt operations to fail with -4304.  But in iOS 4 the operations would still move the data they had decrypted (which was essentially all of it), while iOS 5 changed such that all data movement was suppressed if the operation failed (and the last block would almost always fail).</p>
  <p>Turning off the padding option makes the code work without posting any errors.</p>