Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From <a href="https://developer.apple.com/library/ios/documentation/System/Conceptual/ManPages_iPhoneOS/man3/CCCryptor.3cc.html" rel="nofollow">docs</a>:</p> <pre><code>CCCrypt(CCOperation op, CCAlgorithm alg, CCOptions options, const void *key, size_t keyLength, const void *iv, const void *dataIn, size_t dataInLength, void *dataOut, size_t dataOutAvailable, size_t *dataOutMoved); </code></pre> <p>The second last parameter <code>dataOutAvailable</code> should be the length of the previous parameter, which should be equal to the input size plus the size of one block.</p> <blockquote> <p>For stream ciphers, the output size is always equal to the input size, and CCCryptorFinal() never produces any data. For block ciphers, the output size will always be less than or equal to the input size plus the size of one block.</p> </blockquote> <p>So, in your case, you should define <code>unencryptedData</code> like the following:</p> <pre><code>uint8_t unencryptedData[dataLength + kCCBlockSizeAES128]; /// kCCBlockSizeAES128 instead of kCCKeySizeAES128 </code></pre> <p>And pass the length of <code>unencryptedData</code> array instead of the length of input data:</p> <pre><code>size_t unencryptedDataLength = dataLength + kCCBlockSizeAES128; CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionECBMode, key, kCCKeySizeAES128, NULL, [data bytes], dataLength, unencryptedData, unencryptedDataLength, &amp;unencryptedLength); </code></pre> <p>And by the way, you can use <a href="https://github.com/rnapier/RNCryptor" rel="nofollow">RNCryptor</a> library which is CCCryptor wrapper for iOS and Mac.</p> <p><em><strong>Update</em>:</strong></p> <p>Try running all background decryption operations on a single serial dispatch queue. To create a serial dispatch queue:</p> <pre><code>dispatch_queue_t decryptionQueue = dispatch_queue_create("DecryptionQueue", NULL); </code></pre> <p>And then use it instead of the global queue you were using:</p> <pre><code>dispatch_async(decryptionQueue, ^(void){ ... }); </code></pre> <p>Make sure to use the same queue and not create a new one every time.</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