Padding is part of Block cipher implementation.
Refer to
http://msdn.microsoft.com/en-us/library/system.security.cryptography.paddingmode(v=vs.110).aspx[
^]
If you are using 8 block cipher,
If you want to encrypt 9 bytes data
FF FF FF FF FF FF Ff Ff FF
Using PaddingMode.ANSIX923
7 bytes will be added so that we have whole number of blocks, ie 2 blocks of 8 bytes
The blocks would be
FF FF FF FF FF Ff Ff Ff FF 00 00 00 00 00 00 07
The right bytes of the appended bytes in the padded block indicates how many byte in the blocks are unused. This will allow such unused padding bytes to be remove in the decryption process.
If you examine the sample in
http://msdn.microsoft.com/en-us/library/0dh224hh(v=vs.110).aspx[
^]
the data is "Here is some data to encrypt." , 29 bytes
It gets encrypted to file that has a length of 32 bytes
But, when you decrypts the file, you get back the 29 bytes data.
You may also want to refer to a recent CP article
Swanky encryption/decryption in C#[
^]
You will note that the implmentation save encrypted data to file, but then read out the encrypted data to buffer, decrypt to buffer and then save the decrypted data back to file. Note that the saved decrypted file is the same length as the original file. But the encrypted file is always slightly larger ( file length is a multiple of block size ).