|
```text
5.2.1 Padding
Since the data being encrypted is an arbitrary number of octets, it may
not be a multiple of the block size. This is solved by padding the plain
text up to the block size before encryption and unpadding after
decryption. The padding algorithm is to calculate the smallest non-zero
number of octets, say N, that must be suffixed to the plain text to
bring it up to a multiple of the block size. We will assume the block
size is B octets so N is in the range of 1 to B. Pad by suffixing the
plain text with N-1 arbitrary pad bytes and a final byte whose value is
N. On decryption, just take the last byte and, after sanity checking it,
strip that many bytes from the end of the decrypted cipher text.
For example, assume an 8 byte block size and plain text of 0x616263. The
padded plain text would then be 0x616263????????05 where the "??" bytes
can be any value. Similarly, plain text of 0x2122232425262728 would be
padded to 0x2122232425262728??????????????08.
```
* https://www.w3.org/TR/xmlenc-core1/#sec-Alg-Block
|