示例#1
0
        //private static Hashtable certificateErrors = new Hashtable();

        //// The following method is invoked by the RemoteCertificateValidationDelegate.
        //public static bool ValidateServerCertificate(
        //      object sender,
        //      X509Certificate certificate,
        //      X509Chain chain,
        //      SslPolicyErrors sslPolicyErrors)
        //{
        //    if (sslPolicyErrors == SslPolicyErrors.None)
        //        return true;

        //    Console.WriteLine("Certificate error: {0}", sslPolicyErrors);

        //    // Do not allow this client to communicate with unauthenticated servers.
        //    return false;
        //}


        static void Main(string[] args)
        {
            //IPAddress ip = IPAddress.Parse("127.0.0.1");
            //int port = 5000;
            //TcpClient client = new TcpClient();
            //client.Connect(ip, port);
            //Console.WriteLine("client connected!!");
            //NetworkStream ns = client.GetStream();
            //SslStream sslStream = new SslStream(
            //   ns,
            //   false,
            //   new RemoteCertificateValidationCallback(ValidateServerCertificate),
            //   null
            //   );
            //Thread thread = new Thread(o => ReceiveData((TcpClient)o));

            //thread.Start(client);

            //string s;
            //while (!string.IsNullOrEmpty((s = Console.ReadLine())))
            //{
            //    byte[] buffer = Encoding.ASCII.GetBytes(s);
            //    ns.Write(buffer, 0, buffer.Length);
            //}

            //client.Client.Shutdown(SocketShutdown.Send);
            //thread.Join();
            //ns.Close();
            //client.Close();
            //Console.WriteLine("disconnect from server!!");
            //Console.ReadKey();
            SslTcpClient SslTcpClient = new SslTcpClient();
        }
示例#2
0
        public SslTcpClient()
        {
            var machineName               = "127.0.0.1";                                               //servers IP or websiteName
            var serverCertificateName     = "localhost";                                               // certificate Name
            var clientCertificatePath     = "C:\\Program Files\\OpenSSL - Win64\\bin\\serverCert.cer"; // certificate Path
            var clientCertificatePassword = "******";                                               // certificate Path

            SslTcpClient.RunClient(machineName, serverCertificateName, clientCertificatePath, clientCertificatePassword);
            Console.ReadKey();
        }