In here different byte padding standards are listed as ANSI X.923, ISO 101.26, PKCS7, ISO/IEC 7816-4 and zero padding. All of them seems to apply padding to the last byte blocks. Odds are rare but what happens if the actual data is an integer product of the block size and last bytes conflict with a padding scheme.

For example, for PKCS7 let last 8 bytes be


01 may actually be original data or padding. How do we know this? How do we avoid a data loss? (It seems trivial but image formats may become corrupted, because original data size changes.)


Padding is always added, even if the plaintext is a product of the block size. This way the algorithm look for the last byte(s) and can safely interpret it as padding data. In case of alignment to the block size, a full block is added just for padding purposes.

So if your example shows 8 bytes of data and you are using a 64-bit block cipher, a block of eight 08 would be added as padding.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy