Archived Forum Post

Index of archived forum posts

Question:

iOS 6 decrypting in simulator but not on device

Sep 19 '12 at 18:05

I have a method that encrypts and decrypts in the iOS 6 simulator but does not decrypt on the device. No errors seem to occur and all objects appear to be initialized in the debugger using the device.

Code CkoCrypt2 *crypt = [[CkoCrypt2 alloc] init]; crypt.VerboseLogging = YES; BOOL success; success = [crypt UnlockComponent:xxxx]; if (success != YES) { return nil; } // AES is also known as Rijndael. crypt.CryptAlgorithm = @"aes";

//  CipherMode may be "ecb" or "cbc"
crypt.CipherMode = @"cbc";

//  KeyLength may be 128, 192, 256
crypt.KeyLength = [NSNumber numberWithInt:256];

crypt.PaddingScheme = [NSNumber numberWithInt:0];

crypt.EncodingMode = @"base64";

NSString *ivHex;
ivHex = X;
[crypt SetEncodedIV: ivHex encoding: @"hex"];

NSString *keyHex;
//keyHex = [crypt GenEncodedSecretKey:password encoding:@"hex"];
keyHex = @"000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F";
[crypt SetEncodedKey: keyHex encoding: @"hex"];

//  Now decrypt:
NSString *decStr;
decStr = [crypt DecryptStringENC: @"b7d0QF97DRKz6UCkfrVg2Q=="];

NSString *enc = [crypt EncryptStringENC:@"12345"];
NSLog(@"Decrypt: %@",decStr);
NSLog(@"%@", crypt.LastErrorText);
NSLog(@"DECRYPT: %@", [crypt DecryptStringENC:enc]);
[crypt release];
return decStr;

Device:

2012-09-18 15:25:55.459 xxxx[5844:907] Decrypt: 
2012-09-18 15:25:55.461 xxxht[5844:907] ChilkatLog:
  EncryptStringENC:
    DllDate: Sep 13 2012
    UnlockPrefix:xxx
    Username: xxxs-iPad:mobile
    Architecture: Little Endian; 32-bit
    Language: IOS Objective-C
    VerboseLogging: 1
    EncryptionParams:
      algorithm: aes
      keyLength: 256
      paddingScheme: 0
      cipherMode: cbc
      encodingMode: base64
      charset: windows-1252
      secretKey: 0001 0203 0405 0607 0809 0A0B 0C0D 0E0F
1011 1213 1415 1617 1819 1A1B 1C1D 1E1F
      iv: 0201 6203 0415 0608 0809 1A2B 0C1D 6E0F
      inDataNumBytes: 5
      inData: 3132 3334 35
    --EncryptionParams
    algorithm: aes
    keyLength: 256
    encryptedData: C8AD 9D60 962D 1923 E611 3747 7C16 9896
    Success.
  --EncryptStringENC
--ChilkatLog
2012-09-18 15:25:55.463 xxxt[5844:907] DECRYPT: 

In Sim 2012-09-18 15:30:49.753 xxxht[50234:1a903] Decrypt: NORTH RALEIGH 2012-09-18 15:30:49.754 xxxt[50234:1a903] ChilkatLog: EncryptStringENC: DllDate: Sep 13 2012 UnlockPrefix:xxx Username: J-Andersons-iMac.local:administrator Architecture: Little Endian; 32-bit Language: IOS Objective-C VerboseLogging: 1 EncryptionParams: algorithm: aes keyLength: 256 paddingScheme: 0 cipherMode: cbc encodingMode: base64 charset: windows-1252 secretKey: 0001 0203 0405 0607 0809 0A0B 0C0D 0E0F 1011 1213 1415 1617 1819 1A1B 1C1D 1E1F iv: 0201 6203 0415 0608 0809 1A2B 0C1D 6E0F inDataNumBytes: 5 inData: 3132 3334 35 --EncryptionParams algorithm: aes keyLength: 256 encryptedData: 9415 AF5F 59EB 333C 94D5 0B59 D8B3 56B6 Success. --EncryptStringENC --ChilkatLog 2012-09-18 15:30:49.754 ixxx[50234:1a903] DECRYPT: 12345


Answer

Thanks. There seems to be something amiss with AES on iOS6. You've provided the LastErrorText for the EncryptStringENC method calls, but not for the DecryptStringENC method calls. Please post those so we can see what transpired within the DecryptStringENC calls.


Answer

This new build should solve the problem:

http://www.chilkatsoft.com/preRelease/Chilkat-9.3.2-IOS-6.0.zip

There have been numerous issues reported by many Chilkat customers having to do with the new iOS 6 device builds (the simulator build is reported to work in all cases).

The solution was to build the Chilkat libs with a lower compiler optimization setting. There must be some invalid optimized code produced by the llvm-gcc-4.2 for the armv7 and armv7s devices. The optimization has been changed from "-Os" to "-O1". This has solved the problems of all customers that have so far tested the new build.