System.Security.Cryptography.AesCryptoServiceProvider.Dispose C# (CSharp) Method

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                _impl.Dispose();
                base.Dispose(disposing);
            }
        }
    }

Usage Example

        static void Decrypt(string[] args)
        {
            //Precheck if a tmp file already exists.
            //If so delete it.
            if (File.Exists(args[0] + ".tmp"))
            {
                Display("Destroying old .tmp files.");
                DestroyFile(args[0] + ".tmp");
                Display("Done.");
            }

            //SET UP STREAMS//
            FileStream Output;
            FileStream Input;
            CryptoStream CryptStream;

            //SET UP SERVICE PROVIDERS//
            AesCryptoServiceProvider ACSP = new AesCryptoServiceProvider();

            //AES PARAMETERS//
            ACSP.Padding = PaddingMode.PKCS7;
            Display("Creating keys.");
            ACSP.IV = GenerateIV(args[2]);      //initialization vector
            ACSP.Key = GenerateKey(args[2]);    //32 byte key
            Display("Done.");

            Input = new FileStream(args[0], FileMode.Open);
            Output = new FileStream(args[0] + ".tmp", FileMode.CreateNew);
            CryptStream = new CryptoStream(Input, ACSP.CreateDecryptor(), CryptoStreamMode.Read);

            Display("Starting decryption.");
            CryptStream.CopyTo(Output);
            Display("Done.");
            Input.Flush();
            Input.Dispose();
            CryptStream.Flush();
            //CryptStream.Dispose(); <-- Is disposed with input.
            Output.Flush();
            Output.Dispose();

            Display("Destroying old raw file.");
            DestroyFile(args[0]);
            Display("Done.");

            //Rename .tmp to the original file.
            Display("Renaming new file.");
            File.Move(args[0] + ".tmp", args[0]);
            Display("Done.");

            ACSP.Dispose();

            Display("Decryption process completed.");
            Console.ReadKey();
            return;
        }
All Usage Examples Of System.Security.Cryptography.AesCryptoServiceProvider::Dispose