Ejemplo n.º 1
0
        public void SecureReadWriteTest()
        {
            var location = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            using (var stream1 = new MemoryStream())
                using (var stream2 = new MemoryStream())
                    using (var requestSend = new EncryptedStream(stream1, canDispose: false))
                        using (var requestReceive = new EncryptedStream(stream2, canDispose: false))
                        {
                            byte[] data = Encoding.UTF8.GetBytes("changeit");
                            requestSend.Write(data, 0, data.Length);
                            requestSend.Flush();

                            var streamData = stream1.ToArray();
                            Console.WriteLine(string.Join(" ", data.Select(m => $"{m:X2}").ToArray()));

                            Console.WriteLine(streamData.Length);
                            Console.WriteLine(string.Join(" ", streamData.Select(m => $"{m:X2}").ToArray()));

                            TransferData(requestSend, requestReceive);
                            byte[] data1 = new byte[data.Length];
                            int    count = requestReceive.Read(data1, 0, data1.Length);
                            Assert.AreEqual(data.Length, count);

                            var str = Encoding.UTF8.GetString(data1);
                            Assert.AreEqual("changeit", str);
                        }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            IStream stream = new EncryptedStream(new CompressedStream(new Stream()));

            stream.Write("stream");

            Console.ReadKey();
        }