3

We are creating same project in android and iphone. Now problem is that we need to send user information to aspx server using webservice in encrypted form. We both have implemented it but results are diiferent so is there a common AES encryption method which will produce same result and can be parsed at server.

Please reply as soon as possible, my work get affected because of it.

Thanks in advance

Soniya
  • 600
  • 7
  • 34
  • 1
    Is there any chance you can post code which you wrote for common encryption ? We are trying to achieve same and stuck since 2 days. – Janak Nirmal Aug 01 '12 at 10:30
  • Hey there my mate and me made it have a look at this post http://stackoverflow.com/questions/17535918/aes-gets-different-results-in-ios-and-java/19219704#19219704 – A.S. Oct 07 '13 at 09:36
  • I just posted an acceptable answer in https://stackoverflow.com/questions/40421146/aes-cbc-pkcs5padding-in-ios-objective-c-result-differs-from-android/56178213#56178213. – Julian Corrêa May 17 '19 at 01:05
  • Possible duplicate of [AES string encryption in Objective-C](https://stackoverflow.com/questions/7289870/aes-string-encryption-in-objective-c) – Julian Corrêa Nov 19 '19 at 14:47

3 Answers3

2

You could consider using the RNCryptor library for iOS and the JNCryptor library for Android. Both open-source libraries use the same data format and have support for password-based encryption and key-based encryption using 256-bit AES.

The data format also includes the IV and a MAC value calculated across the data, so it conforms with the best practices for data encryption.

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
0

AES encryption/decryption will produce the same results on it it is provided the same parameters. Of particular interest are

  1. encryption key value and size
  2. mode: CBC, ECB, etc. (you should probably be using CBC)
  3. initialization vector (iv) is needed for most modes
  4. padding method: PKCS7, etc. (AES is a block cypher and needs input in a multiple of block size)

As a start chose simple test data, get that working and move into more complex situations. Ex: initially choose an iv of all 0, CBC, data of exactly one block size with no padding. When that is working start adding in more complexity.

Security is not easy, the encryption part is the easy part.

Or use SSL.

For reference and learning basically everything one needs to know is in the Handbook of Applied Cryptography it is a free (and legal) pdf download, a hardcover version can also be purchased. Pros use this book, even my wife in her work.

zaph
  • 111,848
  • 21
  • 189
  • 228
  • Thanks a lot for replying. But sir I am very new in this field and never done encyption before So I didnt get how to do it and from where to start. How this code will look in android and how i implement in iphone. I am just blank. Can you tell me with some example or provide some code snippet for both android and iphone. – Soniya Oct 07 '11 at 10:12
  • Sir android team already used the approch in following link can there is a way to implement same in iphone or some other method which we both can follow.http://stackoverflow.com/questions/5277533/aes-key-generation-in-android/7685963#7685963 – Soniya Oct 08 '11 at 05:19
  • Sir any website where I can understand every thing. and how to implement, how CBC,ECB works etc. – Soniya Oct 08 '11 at 05:20
0

I have some similar problem working with AES encryption on java and iOS, check my question and the answer, maybe it can help you, the ECB mode is only supported on iOs

Objective-c AES encryption doesn't look like java AES encryption

Community
  • 1
  • 1
JonLOo
  • 4,929
  • 1
  • 19
  • 27
  • iOS (CommonCrypto) supports both CBC and ECB, CBC is the default. Do not simple go by the header (.h) files, in this case the .h file does not provide the default values. – zaph Oct 06 '11 at 12:35
  • From the Apple header file CommonCryptor.h: Initialization vector, optional. Used by block ciphers when Cipher Block Chaining (CBC) mode is enabled. If present, must be the same length as the selected algorithm's block size. ***If CBC mode is selected (by the absence of the kCCOptionECBMode bit in the options flags)*** and no IV is present, a NULL (all zeroes) IV will be used. – zaph Oct 06 '11 at 13:05
  • Sir android team already used the approch in following link can there is a way to implement same in iphone or some other method which we both can follow. http://stackoverflow.com/questions/5277533/aes-key-generation-in-android/7685963#7685963 I am very new in this field and never done encyption before So I didnt get how to do it and from where to start. How this code will look in android and how i implement in iphone. I am just blank. Can you tell me with some example or provide some code snippet for both android and iphone. Thx in advance – Soniya Oct 07 '11 at 10:25
  • I looked at the have code, unfortunately I do not know the java security API and could not get any real information from it. First you will need to know what the have code is doing, get the answers to the four points in my answer. – zaph Oct 07 '11 at 13:34
  • Sir any website where I can understand every thing. and how to implement, how CBC – Soniya Oct 08 '11 at 05:20
  • try using this: `kCCOptionPKCS7Padding & kCCModeCBC` – Ankit Malhotra Feb 22 '14 at 16:31