public void ServiceChannel070Test()
        {
            var location = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            using (var stream1 = new MemoryStream())
                using (var stream2 = new MemoryStream())
                    using (var clientChannel = new ServiceChannel())
                        using (var serviceChannel = new ServiceChannel())
                        {
                            serviceChannel.SetReadStream(stream1, false);
                            serviceChannel.CipherLib["rsa-private"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem", $"{location}\\data\\server\\server.pem.key");

                            clientChannel.SetWriteStream(stream2, false);
                            clientChannel.CipherLib["rsa-public"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem");
                            clientChannel.Encrypt();

                            var data = Security.Random.Get(128 * 1024 + 1);
                            clientChannel.Encrypt();
                            clientChannel.Write(data);

                            clientChannel.Flush();
                            Console.WriteLine(stream2.Length);

                            TransferData(stream2, stream1);
                            var data1 = serviceChannel.Read();
                            Assert.AreEqual(Hash.MD5(data), Hash.MD5(data1));
                        }
        }
        public void ServiceChannel060Test()
        {
            var location = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            using (var stream1 = new MemoryStream())
                using (var stream2 = new MemoryStream())
                    using (var clientChannel = new ServiceChannel())
                        using (var serviceChannel = new ServiceChannel())
                        {
                            serviceChannel.SetReadStream(stream1, false);
                            //serviceChannel.CipherLib["rsa-private"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem", $"{location}\\data\\server\\server.pem.key");

                            clientChannel.SetWriteStream(stream2, false);

                            clientChannel.Encrypt();
                            clientChannel.WriteObject("HELO");

                            clientChannel.CipherLib["rsa-public"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem");
                            clientChannel.Encrypt();
                            clientChannel.WriteObject("HELO2");

                            clientChannel.Flush();
                            Console.WriteLine(stream2.Length);

                            TransferData(stream2, stream1);
                            var msg = serviceChannel.ReadObject <string>();
                            Assert.AreEqual("HELO", msg);

                            Assert.Catch <SecureChannelException>(() =>
                            {
                                var msg2 = serviceChannel.ReadObject <string>();
                            });
                        }
        }
        public void ServiceChannel010Test()
        {
            var location = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            using (var stream1 = new MemoryStream())
                using (var stream2 = new MemoryStream())
                    using (var stream11 = new MemoryStream())
                        using (var stream21 = new MemoryStream())
                            using (var clientChannel = new ServiceChannel())
                                using (var serviceChannel = new ServiceChannel())
                                {
                                    serviceChannel.SetReadStream(stream1, false);
                                    serviceChannel.CipherLib["rsa-private"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem", $"{location}\\data\\server\\server.pem.key");

                                    clientChannel.SetWriteStream(stream2, false);
                                    clientChannel.CipherLib["rsa-public"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem");
                                    //clientChannel.CipherLib["rsa-private"] = RsaCipher.LoadFromPEM($"{location}\\data\\client\\test-user\\cer.pem", $"{location}\\data\\client\\test-user\\cer.pem.key");

                                    clientChannel.Encrypt();
                                    clientChannel.WriteObject("HELO");
                                    clientChannel.Flush();

                                    clientChannel.SetReadStream(stream21, false);

                                    Console.WriteLine(stream2.Length);

                                    TransferData(stream2, stream1);

                                    var value = serviceChannel.ReadObject <string>();
                                    Console.WriteLine(value);
                                    Assert.AreEqual("HELO", value);

                                    //clientChannel.CipherLib["rsa-public"] = RsaCipher.LoadFromPEM($"{location}\\data\\client\\test-user\\cer.pem");

                                    serviceChannel.SetWriteStream(stream11, false);
                                    serviceChannel.Encrypt();
                                    serviceChannel.WriteObject("EHLO");
                                    serviceChannel.Flush();

                                    Console.WriteLine(stream11.Length);
                                    TransferData(stream11, stream21);

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

                                    var value1 = clientChannel.ReadObject <string>();
                                    Console.WriteLine(value1);
                                    Assert.AreEqual("EHLO", value1);
                                }
        }
        public void ServiceChannel020Test()
        {
            var location = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            using (var stream1 = new MemoryStream())
                using (var stream2 = new MemoryStream())
                    using (var stream11 = new MemoryStream())
                        using (var stream21 = new MemoryStream())
                            using (var clientChannel = new ServiceChannel())
                                using (var serviceChannel = new ServiceChannel())
                                {
                                    serviceChannel.SetReadStream(stream1, false);
                                    clientChannel.SetWriteStream(stream2, false);

                                    clientChannel.Encrypt();
                                    clientChannel.WriteObject("HELO");
                                    clientChannel.Flush();

                                    clientChannel.SetReadStream(stream21, false);

                                    Console.WriteLine(stream2.Length);

                                    TransferData(stream2, stream1);

                                    var value = serviceChannel.ReadObject <string>();
                                    Console.WriteLine(value);
                                    Assert.AreEqual("HELO", value);

                                    serviceChannel.SetWriteStream(stream11, false);
                                    serviceChannel.Encrypt();
                                    serviceChannel.WriteObject("EHLO");
                                    serviceChannel.Flush();

                                    Console.WriteLine(stream11.Length);
                                    TransferData(stream11, stream21);

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

                                    var value1 = clientChannel.ReadObject <string>();
                                    Console.WriteLine(value1);
                                    Assert.AreEqual("EHLO", value1);
                                }
        }