login about faq

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>
With the Xcode 4.5 i have this encoded Key: <cab07efc ff07ce85 7f96b975 55a9df0d>

asked Sep 14 '12 at 13:42

chilkat's gravatar image

chilkat ♦♦
11.8k316358421


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"];

link

answered Sep 14 '12 at 13:51

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

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.

link

answered Sep 19 '12 at 18:04

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×64
×33
×13

Asked: Sep 14 '12 at 13:42

Seen: 2,321 times

Last updated: Sep 19 '12 at 18:04

powered by OSQA