I have a problem that the encrypted code in Xcode 4.5 is not equal with the encrypted code in Xcode 4.4.
Here are my code:
CkoCrypt2 *crypt = [[[CkoCrypt2 alloc] init] autorelease]; [crypt UnlockComponent:@"unlockcode"]; crypt.CryptAlgorithm = @"aes"; crypt.CipherMode = @"cbc"; crypt.KeyLength = [NSNumber numberWithInt:256]; crypt.PaddingScheme = [NSNumber numberWithInt:3]; crypt.EncodingMode = @"hex"; NSString *ivHex = @"12345678"; [crypt SetEncodedIV:ivHex encoding:@"hex"]; NSString *keyHex = @"90ABCDEF"; [crypt SetEncodedKey:keyHex encoding:@"hex"]; NSData *enc = [crypt EncryptString:@"12345"];
With the Xcode 4.4 i have this encoded Key: <49a2de44 6feb08f6 c686ea5f 08f46e70>
asked Sep 14 '12 at 13:42
NOTE: Providing the correct number of bytes for the IV and secret key is needed, but it's not the entire solution to this problem. See the 2nd answer below...
One problem is that your application did not provide enough bytes for the IV (initialization vector) and the secret key. The AES encryption algorithm has a block size of 16 bytes (regardless of key length), and therefore the IV should always be 16 bytes in length. The code snippet above only provides 4 bytes.
The following call:
NSString *ivHex = @"12345678"; [crypt SetEncodedIV:ivHex encoding:@"hex"];
Because the 2nd arg indicates "hex", the above call provides these 4 bytes: 0x12 0x34 0x56 and 0x78. You must provide all 16 bytes. For example:
NSString *ivHex = @"0102030405060708090A0B0C0D0E0F"; [crypt SetEncodedIV:ivHex encoding:@"hex"];
Likewise, because the KeyLength is set to 256 bits, you must provide 32 bytes of key material (32 x 8 bits/byte = 256 bits). Your application is only providing 4 bytes: 0x90 0xAB 0xCD 0xEF. You need to provide all 32 bytes, such as:
NSString *keyHex = @"0102030405060708090A0B0C0D0E0F0102030405060708090A0B0C0D0E0F"; [crypt SetEncodedKey:keyHex encoding:@"hex"];
answered Sep 14 '12 at 13:51
This new build should solve the problem:
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.
answered Sep 19 '12 at 18:04