Esempio n. 1
0
        private static async Task <(MemoryStream output, IMS2SizeHeader size)> InternalGetEncryptionStreamAsync(Stream input, long inputSize, IBufferedCipher cipher, long headerSize)
        {
            byte[] inputBytes = new byte[inputSize];
            int    read       = await input.ReadAsync(inputBytes, 0, (int)inputSize).ConfigureAwait(false);

            if (inputSize != read)
            {
                throw new EndOfStreamException();
            }
            using var msInput = new MemoryStream(inputBytes);

            using var cs = new CipherStream(msInput, cipher, null);
            using var ms = new MemoryStream();

            var output = new MemoryStream();
            await cs.CopyToAsync(ms).ConfigureAwait(false);

            var data    = ms.ToArray();
            var encoder = new Base64Encoder();

            encoder.Encode(data, 0, data.Length, output);

            var header = new MS2SizeHeader(output.Length, inputSize, headerSize);

            output.Position = 0;
            return(output, header);
        }