See Also: CryptoStream Members
The common language runtime uses a stream-oriented design for cryptography. The core of this design is System.Security.Cryptography.CryptoStream. Any cryptographic objects that implement System.Security.Cryptography.CryptoStream can be chained together with any objects that implement System.IO.Stream, so the streamed output from one object can be fed into the input of another object. The intermediate result (the output from the first object) does not need to be stored separately.
You should always explicitly close your System.Security.Cryptography.CryptoStream object after you are done using it by calling the System.IO.Stream.Close method. Doing so flushes the stream and causes all remain blocks of data to be processed by the System.Security.Cryptography.CryptoStream object. However, if an exception occurs before you call the System.IO.Stream.Close method, the System.Security.Cryptography.CryptoStream object might not be closed. To ensure that the System.IO.Stream.Close method always gets called, place your call to the System.IO.Stream.Close method within the finally block of a try/catch statement.