0

I am working on the cross platform (IOS, ANDROID) AES 256 Encryption Library. Now, when I try to add encryption to the image object it adds 16 bytes in iOS and around 8KB in Android. Here is the problem. Why is it so? Could anybody explain me why is there a difference in such padding. Basically I am breaking the image data into chunks of 10240 bytes. If I add encryption to it the size that is returned is 10256 bytes but in Android it is encrypting it with 18699 bytes. So, How do I figure this mismatch in the bytes returned in cross platform.

user1512727
  • 41
  • 1
  • 5
  • 4
    Please show the necessary parts of your code by editing them into your question. – Artjom B. Feb 20 '15 at 08:26
  • 1) If PKCS#7 padding is used then encrypted data will be a multiple of the block size and this may require adding an extra block. 2) If the Android data is 8KB larger that is probably because they are adding an encoding of the encrypted data, perhaps Base64 or Hex. Encryption does not change the size of the data albeit using padding may add an extra block to the data. – zaph Feb 20 '15 at 12:24
  • @Zaph: Thanks for the information. Could you let me know how can I add extra block to it in iOS. – user1512727 Feb 20 '15 at 14:46
  • The extra block is why you are getting 10256 for 10240 bytes of input. If the data is is exactly a block size multiple an extra block has to be added (for PKCS#7 padding). There are several AES implementations [here on SO](http://stackoverflow.com/a/7409516/451475): – zaph Feb 20 '15 at 17:31
  • Are you the author or are you *using* the library? **That library should not be used at all, it is not secure.** – Maarten Bodewes Feb 24 '15 at 19:23

0 Answers0