Beispiel #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;
			}
		}