Example #1
0
        private void BeginCommunication(Socket handler)
        {
            try
            {
                bool isComm = isCommunication();
                if (!isComm)
                {
                    handler.Send(Encoding.UTF8.GetBytes(Properties.NO_COMMUNICATION));
                    return;
                }


                string    privateKey = Properties.getPrivateKey();
                PublicKey publicKey  = Properties.getPublicKey();

                char[] sendKey = CriptoUtils.createSesionKey(publicKey, privateKey.ToCharArray());
                handler.Send(Encoding.UTF8.GetBytes(sendKey));

                string recvKey = SocketUtils.RecvData(handler);
                Console.WriteLine(recvKey.Length + " " + privateKey.Length);
                char[] sessionKey = CriptoUtils.createSesionKey(new PublicKey(recvKey, publicKey.mod), privateKey.ToCharArray());
                Properties.setSessionKey(new string(sessionKey));
                string encodedString = CriptoUtils.Encrypt(Properties.TEST_COMMUNICATON, Properties.getSessionKey());
                handler.Send(Encoding.UTF8.GetBytes(encodedString));
                mainWindow.write(SocketClient.SUCCESS);
                mainWindow.setEnabledSend();
            }
            catch (Exception e)
            {
                mainWindow.write("Не удалось установить соединение по причине: " + e.Message);
            }
        }