public ServerSSL(int port) { Listener = new TcpListener(IPAddress.Any, port); client = null; _StreamSSL = new StreamSSL() { DecryptOutput = (byte[] buffer, int offset, int count) => { string msg = Encoding.UTF8.GetString(buffer, offset, count); Console.Write("Recv:" + msg); msg = msg.ToUpper(); _StreamSSL.Encrypt(msg); return(true); } }; X509Cert = new X509Certificate2("E:/MessageFramework/SelfCert.pfx", "messageframework"); }
bool SendSSL(Byte[] buffer, Int32 offset, Int32 count) { try { return(_StreamSSL.Encrypt(buffer, offset, count)); } catch (Exception ex) { Close(ex); } return(false); }
public bool Start(string host, int port) { try { _ClientSocket.Connect(host, port); Console.WriteLine("Client connected."); if (!_StreamSSL.AuthenticateAsClient(_ClientSocket, SslProtocols.Tls12)) { return(false); } new Thread(ThreadReceive).Start(); byte[] messsage = Encoding.UTF8.GetBytes("Hello from the client.<EOF>\n"); // Send hello message to the server. _StreamSSL.Encrypt(messsage, 0, messsage.Length); do { string msg = Console.ReadLine() + "\n"; // Send hello message to the server. //messsage = Encoding.UTF8.GetBytes(msg); _StreamSSL.Encrypt(msg, Encoding.UTF8); if (msg == "exit") { break; } } while (true); // Close the client connection. _ClientSocket.Close(); Console.WriteLine("Client closed."); return(true); } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex.Message); Close(); } return(false); }
protected override bool Send(Byte[] buffer, Int32 offset, Int32 count) { return(_StreamSSL.Encrypt(buffer, offset, count)); }