The documentation is currently being reviewed, so you may see some inconsistencies between sections.
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Padding

Purpose

The length of a ciphertext from a stream cipher is equal to the length of the plaintext. In most cases, this is not considered an issue. However, hiding the length of a message can be desirable, and ISO/IEC 7816-4 padding can be used to do this.

The amount of padding, determined by the block size, can either be deterministic or randomised. Both have their strengths and weaknesses.

Usage

Fill

Fills a span with padding. This can then be manually concatenated with some data.

Iso78164Padding.Fill(Span<byte> buffer)

Exceptions

ArgumentOutOfRangeException

buffer has a length of 0.

GetPaddedBufferSize

Returns the required buffer size for Pad() based on the unpadded data length and a block size (e.g., 16 bytes).

Exceptions

ArgumentOutOfRangeException

blockSize is less than or equal to 0.

OverflowException

data.Length + paddingSize has resulted in an overflow.

Pad

Fills a span with the data padded up to the specified block size (e.g., a multiple of 16 bytes).

Exceptions

ArgumentOutOfRangeException

buffer has a length not equal to GetPaddedBufferSize(data, blockSize).

ArgumentOutOfRangeException

blockSize is less than or equal to 0.

CryptographicException

Error padding data.

GetUnpaddedBufferSize

Returns the number of bytes to slice from the end of the padded data.

Exceptions

ArgumentOutOfRangeException

paddedData has a length of 0.

ArgumentOutOfRangeException

blockSize is less than or equal to 0.

FormatException

Invalid padding.

Notes

Last updated