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

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    if (!_finalBlockTransformed)
                    {
                        FlushFinalBlock();
                    }
                    if (!_leaveOpen)
                    {
                        _stream.Dispose();
                    }
                }
            }
            finally
            {
                try
                {
                    // Ensure we don't try to transform the final block again if we get disposed twice
                    // since it's null after this
                    _finalBlockTransformed = true;
                    // we need to clear all the internal buffers
                    if (_inputBuffer != null)
                        Array.Clear(_inputBuffer, 0, _inputBuffer.Length);
                    if (_outputBuffer != null)
                        Array.Clear(_outputBuffer, 0, _outputBuffer.Length);

                    _inputBuffer = null;
                    _outputBuffer = null;
                    _canRead = false;
                    _canWrite = false;
                }
                finally
                {
                    base.Dispose(disposing);
                }
            }
        }

Usage Example

Ejemplo n.º 1
0
		public Stream Encode(string key, Stream dataStream)
		{
			SymmetricAlgorithm provider = null;
			ICryptoTransform encryptor = null;
			Stream stream = null;
			try
			{
				provider = GetCryptoProvider(null);
				encryptor = provider.CreateEncryptor();
				stream = new CryptoStream(dataStream, encryptor, CryptoStreamMode.Write);
				return stream.WriteSalt(key).DisposeTogetherWith(provider, encryptor);
			}
			catch
			{
				try
				{
					if (provider != null)
						provider.Dispose();
				}
				catch { }
				try
				{
					if (encryptor != null)
						encryptor.Dispose();
				}
				catch { }
				try
				{
					if (stream != null)
						stream.Dispose();
				}
				catch { }
				throw;
			}
		}
All Usage Examples Of System.Security.Cryptography.CryptoStream::Dispose