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

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_hmacSha1 != null)
                    _hmacSha1.Dispose();
                _hmacSha1 = null;
                if (_buffer != null)
                    Array.Clear(_buffer, 0, _buffer.Length);
                if (_password != null)
                    Array.Clear(_password, 0, _password.Length);
                if (_salt != null)
                    Array.Clear(_salt, 0, _salt.Length);
            }
            base.Dispose(disposing);
        }

Usage Example

        private static byte[] AESEncryptData(byte[] Data, byte[] key, byte[] IVSeed)
        {
            byte[] retByte;

            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes rfcDBGen = new Rfc2898DeriveBytes(key, IVSeed, 128);
                encryptor.IV = rfcDBGen.GetBytes(16);
                encryptor.Key = rfcDBGen.GetBytes(32);
                rfcDBGen.Dispose();
                using(MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(Data, 0, Data.Length);
                        cs.Close();
                    }
                    retByte = ms.ToArray();
                }
            }

            return retByte;
        }
All Usage Examples Of System.Security.Cryptography.Rfc2898DeriveBytes::Dispose