mohas
mohas

Reputation: 1931

What are the implications of not using padding with AES?

I have some problem with padding when working with AES algorithm, so what happens if I disable padding checking when encrypting and decrypting data?

Upvotes: 1

Views: 971

Answers (1)

Artjom B.
Artjom B.

Reputation: 61892

AES is a block cipher and only operates on a single block. It needs a mode of operation to encrypt more than one block. If the mode of operation also works only on blocks (like CBC, ECB) then you can't encrypt arbitrary plaintexts. If you disable padding for those modes, you will need to supply plaintexts that are exactly a multiple of the block size (128-bit for AES).

This is not necessary for modes like CTR or GCM which are streaming modes. They don't require/support padding.

If for some reason, you're not able to make the default PKCS#5/PKCS#7 padding work, you can opt for a ZeroPadding which appends only 0x00 bytes to the plaintext up until a multiple of the block size is reached. This has the implication that the original plaintext cannot end with 0x00 bytes, because they would be removed during decryption. You can of course use any type of filler byte as long as it is not possible for it to appear in the plaintext at the end.

Upvotes: 1

Related Questions