SymmetricAlgorithm: PaddingMode

PaddingMode

A defined set of padding modes used to fill the end of non-blocksize length data blocks. For example if an algorithm has a blocksize of 8 bytes and the data is 3 bytes in length, then 5 bytes of padding must be applied.

 Public Enum PaddingMode

Values

None = 1
No padding is applied to the data.
PKCS7 = 2
The padding that is used is defined by a pattern of filling the remaining bytes with the numeric value of the padding bytes needed. If 5 bytes of padding are needed, then the 5 bytes would be 05 05 05 05 05.
Zeros = 3
The padded bytes are all equal to zero.
ANSIX923 = 4
The padding that is used is defined by a pattern of bytes set to zero with the last byte having the value of the number of padded bytes added. If 5 bytes of padding are needed, then the 5 bytes would be 00 00 00 00 05.
ISO10126 = 5
The padded bytes are random in value with the last byte being the number of padding bytes. If 5 bytes of padding are needed, then the 5 bytes might be 23 9A 48 7C 05.

Remarks

Most plain text messages do not have an length that is a multiple of the block size to be processed by the cipher. There is usually not enough bytes to completely fill the last block to be processed. In these cases, additional bytes need to be appended to make the final block the same size as the block size being processed.

The reverse is done when decrypting ciphered data back to plain text. The padded bytes are removed.

If a plain text message is 9 bytes long and the block size to be processed is 8 bytes, then two blocks will need to be processed. However, the second block will only have 1 byte, so 7 additional bytes are added for padding.

Data: FF FF FF FF FF FF FF FF FF

None: FF FF FF FF FF FF FF FF FF

PKCS7: FF FF FF FF FF FF FF FF FF 07 07 07 07 07 07 07

ANSIX923: FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 07

ISO10126: FF FF FF FF FF FF FF FF FF 7D 2A 75 EF F8 EF 07

Zeros: FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00

See Also

Project VBCorLib Overview Class SymmetricAlgorithm Overview SymmetricAlgorithm Properties SymmetricAlgorithm Methods Padding (let) ToString