Пример #1
0
        public Stream Decode(string key, Stream dataStream)
        {
            SymmetricAlgorithm provider  = null;
            ICryptoTransform   decryptor = null;
            Stream             stream    = null;

            try
            {
                provider  = GetCryptoProvider(null);
                decryptor = provider.CreateDecryptor();
                stream    = new CryptoStream(dataStream, decryptor, CryptoStreamMode.Read);
                return(stream.ReadSalt(key).DisposeTogetherWith(provider, decryptor));
            }
            catch
            {
                try
                {
                    if (provider != null)
                    {
                        provider.Dispose();
                    }
                }
                catch { }
                try
                {
                    if (decryptor != null)
                    {
                        decryptor.Dispose();
                    }
                }
                catch { }
                try
                {
                    if (stream != null)
                    {
                        stream.Dispose();
                    }
                }
                catch { }
                throw;
            }
        }