I Want to Create Aes 128 Using Cfb Encryption with No Padding in Objective C

iOS library to Encrypt AES128 CFB no padding

I'd suggest pushing OpenSSL into your project, if possible. A quick search for "ios openssl" returns a first hit for Easy inclusion of OpenSSL into iOS projects. See also AES interoperability between .Net and iPhone?

Beware that without padding, you'll need to feed the cipher blocks of the correct size.

Objective C Encryption CFB Mode

CBC can be built using ECB, conceptually it's:

Key K;
InitializationVector IV;
OutputDataStream OS;
Block X;

set X = IV;
for each Block B of data D:
Block E = ECB(K, B ^ X);
set X = E
write E to OS

Objective C AES CBC Encryption with Zero Padding

The Method in CommonCrypto.m

- (NSData *) dataEncryptedUsingAlgorithm: (CCAlgorithm) algorithm
key: (id) key
initializationVector: (id) iv
options: (CCOptions) options
error: (CCCryptorStatus *) error

iv parameter declaration

@param      iv              Initialization vector, optional. Used for 
Cipher Block Chaining (CBC) mode. If present,
must be the same length as the selected
algorithm's block size. If CBC mode is
selected (by the absence of any mode bits in
the options flags) and no IV is present, a
NULL (all zeroes) IV will be used. This is
ignored if ECB mode is used or if a stream
cipher algorithm is selected.

so , you could pass nil value to iv parameter

How can I make my AES encryption identical between Java and Objective-C (iPhone)?

Since the CCCrypt takes an IV, does it not use a chaining block cipher method (such as CBC)? This would be consistant with what you see: the first block is identical, but in the second block the Java version applies the original key to encrypt, but the OSX version seems to use something else.

EDIT:

From here I saw an example. Seems like you need to pass the kCCOptionECBMode to CCCrypt:

ccStatus = CCCrypt(encryptOrDecrypt,
kCCAlgorithm3DES,
kCCOptionECBMode, <-- this could help
vkey, //"123456789012345678901234", //key
kCCKeySize3DES,
nil, //"init Vec", //iv,
vplainText, //"Your Name", //plainText,
plainTextBufferSize,
(void *)bufferPtr,
bufferPtrSize,
&movedBytes);

EDIT 2:

I played around with some command line to see which one was right. I thought I could contribute it:

$ echo "Now then and what is this nonsense all about. Do you know?" | openssl enc -aes-128-ecb -K $(echo 1234567890123456 | xxd -p) -iv 0 | xxd 
0000000: 7a68 ea36 8288 c73d f7c4 5d8d 2243 2577 zh.6...=..]."C%w
0000010: e66b 32f9 772b 6679 d7c0 cb69 037b 8740 .k2.w+fy...i.{.@
0000020: 883f 8211 7482 29f4 7239 84be b50b 5aea .?..t.).r9....Z.
0000030: eaa7 519b 65e8 fa26 a1bb de52 083b 478f ..Q.e..&...R.;G.


Related Topics



Leave a reply



Submit