The ICryptoTransform
provides a separate function: TransformFinalBlock
that should be used when encrypting/decrypting the buffer that contains the last block of data, and ensures that necessary padding is added. Since you are only working with a single block, you should be using this method rather than TransformBlock
. Note that returns the encrypted/decrypted data, rather than placing it in a buffer you pass as a parameter.
No answer regarding DES would be complete without mentioning that DES it's insecure, and more generally, that you should be using a unique, random IV each time the data is encrypted, but I'll assume this is mainly for practice, rather than intended for use protecting anything actually sensitive.