The CreateEncryptor method from the Aes class is passed the key and IV that are used for encryption. In this example, the CryptoStream is initialized with a stream object called fileStream that can be any type of managed stream. The instance is used to perform encryption on a CryptoStream class.
The following example illustrates how to create a new instance of the default implementation class for the Aes algorithm.
Using these classes, you can perform symmetric encryption on a variety of stream objects. The CryptoStream class can be initialized using any class that derives from the Stream class, including FileStream, MemoryStream, and NetworkStream. The CryptoStream class is initialized with a managed stream class, a class that implements the ICryptoTransform interface (created from a class that implements a cryptographic algorithm), and a CryptoStreamMode enumeration that describes the type of access permitted to the CryptoStream. The managed symmetric cryptography classes are used with a special stream class called a CryptoStream that encrypts data read into the stream. Asymmetric encryption is performed on a small number of bytes and is therefore useful only for small amounts of data. Symmetric encryption is performed on streams and is therefore useful to encrypt large amounts of data. Symmetric encryption and asymmetric encryption are performed using different processes.