Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.)

share|improve this question
up vote 11 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.