Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I just ran across the exact same problem. I am using CommonCrypto on the iOS client, using settings:</p> <pre><code>NSData * encrypted = [data dataEncryptedUsingAlgorithm:kCCAlgorithmAES128 key:pass initializationVector:iv options:kCCOptionPKCS7Padding error:&amp;status]; </code></pre> <p>The server uses <code>Cipher.getInstance("AES/CBC/PKCS5Padding");</code> with the same key and initialization vector as the client.</p> <p>After banging my head against the wall for the last few hours, I finally followed Jason's advice and checked the <code>dataEncryptedUsingAlgorithm</code> routine and printed out <code>keyData</code> right after <code>FixKeyLengths</code>. It turns out my 128bit key was extended to 192bit with 0s added to the end. After fixing this, everything works properly. :)</p> <p>Update: My answer was posted almost 2 years ago, and this issue seems to be fixed in the latest <a href="https://github.com/AlanQuatermain/aqtoolkit/blob/master/CommonCrypto/NSData+CommonCrypto.m" rel="nofollow">NSData+CommonCrypto</a> code. Specifically, this was the part that caused the issue:</p> <pre><code>static void FixKeyLengths( CCAlgorithm algorithm, NSMutableData * keyData, NSMutableData * ivData ) { NSUInteger keyLength = [keyData length]; switch ( algorithm ) { case kCCAlgorithmAES128: { if ( keyLength &lt;= 16 ) { [keyData setLength: 16]; } else if ( keyLength &lt;= 24 ) { [keyData setLength: 24]; } else { [keyData setLength: 32]; } break; } </code></pre> <p>The first check <code>keyLength &lt;= 16</code> wasn't there before.</p> <p>If you are still experiencing problems now, it's probably something else.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload