Game Development Reference
Ciphers are cryptographic algorithms that use a private key to transform plain text
input into an encrypted output, also known as cipher text . There are two forms of
ciphers: block-based and stream-based.
A block-based cipher takes a fixed size input block and transforms the data into a
fixed size cipher text block.
A stream-based cipher does not encrypt data but instead generates a key stream
that produces the cipher text by XORing the stream bytes with the input bytes.
The .NET Class Framework only provides block-based ciphers, but it is possible to
make a block-based cipher behave in a streaming fashion.
Block ciphers were designed to operate on complete blocks of data. Padding is
used when processing a partial block of data to append extra data to the incom-
plete block, making it an even multiple of the block size.
The .NET 2.0 Class Framework supports three types of block padding, as described
in Table 16.1.
Table 16.1 Padding Modes Available in .NET 2.0
Informs the cipher that no padding should occur. This mode requires that
you ensure that only complete blocks are processed or any exception will
Informs the cipher that zeros should be appended to the incomplete data
block to make it an even multiple of the block size.
The problem with this mode is that the decryption process will not be
able to distinguish the padding from the actual data, which will result in
the padding being appended to the decrypted data.
A possible solution is to transmit the padding length with the data so that
the padding can be removed when the decryption process has finished.
Informs the cipher to append a sequence of bytes that has a value equal
to the number of padding bytes.
In a 128-bit data block, if the source data looks like [AA BB CC DD], then
12 padding bytes must be added to make it an even multiple of the block
size. The hex value [0C] represents the numeric value 12 in base 10, so
the final data block will look like: [AA BB CC DD 0C 0C 0C 0C 0C 0C 0C
0C 0C 0C 0C 0C].