Exemplo n.º 1
0
        public async Task Encrypt(Stream input, Stream output)
        {
            _aes.GenerateIV();

            if (_cancelEvent.IsSet())
            {
                return;
            }

            byte[] vector       = _aes.IV;
            byte[] vectorLength = BitConverter.GetBytes(vector.Length);
            output.Write(vectorLength, 0, 4);
            output.Write(vector, 0, vector.Length);

            if (_cancelEvent.IsSet())
            {
                return;
            }

            using (ICryptoTransform encryptor = _aes.CreateEncryptor())
                using (CryptoStream encryptionStream = new CryptoStream(output, encryptor, CryptoStreamMode.Write))
                {
                    if (_cancelEvent.IsSet())
                    {
                        return;
                    }

                    await PatcherService.CopyAsync(input, encryptionStream, _cancelEvent, Progress);

                    encryptionStream.FlushFinalBlock();
                }
        }
Exemplo n.º 2
0
        private async Task Download(String url, Stream output)
        {
            if (_cancelEvent.WaitOne(0))
            {
                return;
            }

            using (HttpClient client = new HttpClient())
                using (Stream input = await client.GetStreamAsync(url))
                    await PatcherService.CopyAsync(input, output, _cancelEvent, DownloadProgress);
        }
Exemplo n.º 3
0
        public async Task Decrypt(Stream input, Stream output)
        {
            _aes.IV = input.EnsureRead(BitConverter.ToInt32(input.EnsureRead(4), 0));
            Progress.NullSafeInvoke(4);

            using (ICryptoTransform decryptor = _aes.CreateDecryptor())
                using (CryptoStream encryptionStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read))
                {
                    if (_cancelEvent.IsSet())
                    {
                        return;
                    }

                    await PatcherService.CopyAsync(encryptionStream, output, _cancelEvent, Progress);
                }
        }