My Insight

AES ECB encryption with padding and no padding in java language.

Hello There!

When I was creating a code to have an encryption method for AES ECB with PADDING and NO PADDING. Those encryption has an ability to calculate an input value for multiple of 16 bytes on each input as well.

So, here is the calculation if you are using AES ECB encryption with PADDING.

If your input string is less than 16 bytes, it will be automatically PADDING a string into 16 bytes length.

The formula should be something like below :

  • 0 < 16 = 16
  • 16 < 32 = 32
  • 32 < 48 = 48
  • 48 < 64 = 64
  • 64 < 80 = 80
  • So on so forth

The difference for with NO PADDING is, the function itself doesn’t have an input check if the input value is not multiple of 16 bytes. You need to manually give 16 bytes string of data whatever reason is.

NO PADDING will give you an error if the input is not fulfill on its requirements, you will got an error such:

“javax.crypto.IllegalBlockSizeException: Input length not multiple of 16 bytes”

Which is need to be input multiple of 16 bytes as well.


Leave a Reply

Your email address will not be published. Required fields are marked *