4

I've been pulling my hair out over this one. I'm using CommonCrypto in my iOS application to encrypt data which I then send to a Windows server which decrypts it. This works perfectly in the Xcode (latest version) development environment both on my iPhone 5 (iOS 6), iPad 3 (iOS 6) and the simulator (on Mac OS X 10.8.2).

The very simple code I'm using to encrypt is this:

    CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
                                      keyPtr, kCCKeySizeAES128, // oorspronkelijk 256
                                      keyPtr /* initialization vector (optional) */,
                                      [self bytes], dataLength, /* input */
                                      buffer, bufferSize, /* output */
                                      &numBytesEncrypted);

Again, this works great when I'm debugging from Xcode.

But when I build the IPA (archive file, ie. what Apple reviews for the App Store) and send encrypted data to the Windows server, the server reports that the "padding is invalid". There are no code differences between the two!

I suspect that something is different between CommonCrypto in these two build modes, but I can't figure out what that would be. And I tried getting the CommonCrypto library from Apple's open source site and building it, with the intent of compiling it into my code, but I have not been able to build it successfully.

Has anyone else run into this problem? Is there some compiler option I'm missing here?

* EDIT *

I found the flag that is causing the problem: If I set "Optimization Level" to "Smallest/Fastest", "Fastest", "Faster", or "Fast" - it fails. But if I set it to "None", it works. So something in the optimization is causing the encryption to break!

hocker
  • 688
  • 6
  • 18
  • 1
    I would thoroughly check your buffers before issuing a bug report. We cannot, as the relevant code is missing. – Maarten Bodewes Dec 04 '12 at 23:12
  • Thanks for your question. I had a similar situation and the most relevant was this parameter generate different output in development and production if Debug/Release option are different. If you want avoid different behavior we must put the same value in both environments. – Beto Oct 30 '13 at 21:00
  • To clarify, since I obviously missed it somehow, the Optimization Flag mentioned in the OP edit is contained in the Build Settings. THANK YOU HOCKER for finding this!! – iOS4Life Nov 02 '16 at 21:46

0 Answers0