TransformFinalBlock vs CryptoStream

Viewed 334

I am confused about this topic when it comes to AES encryption.

The MSDN page shows quite a lot of code used to encrypt/decrypt and uses multiple streams:

// Create the streams used for encryption.
                using (MemoryStream msEncrypt = new MemoryStream())
                {
                    using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
                    {
                        using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
                        {
                            //Write all data to the stream.
                            swEncrypt.Write(plainText);
                        }
                        encrypted = msEncrypt.ToArray();
                    }
                }
            }

While the video on encryption from MS shows all of this done in a single line:

byte[] plainText = cryptTransform.TransofmrFinalBlock(cipherText, 0, cipherText.Length);

Why would I use the former over the latter? Is there something the first one does that the second on can't?

0 Answers
Related