Beispiel #1
0
        private async void MainForm_Load(object sender, EventArgs e)
        {
            await Task.Delay(3000);

            _connection = new HubConnectionBuilder()
                          .WithUrl("http://localhost:5000/hub")
                          .Build();

            _connection.On <int, int, int>("ReceiveKeys", async(q, a, yb) =>
            {
                var xc = DiffieHellmanService.GetX(q);
                var yc = DiffieHellmanService.GetY(a, xc, q);
                _key   = DiffieHellmanService.GetKey(yb, xc, q);

                await _connection.InvokeAsync("ReceiveKey", (int)yc);

                UserNameTextBox.Enabled = true;
                MessageTextBox.Enabled  = true;
                SendButton.Enabled      = true;
            });

            _connection.On <string, string>("Chat", (name, message) =>
            {
                ChatTextBox.Font = new Font(ChatTextBox.SelectionFont, FontStyle.Bold);
                ChatTextBox.AppendText($"{name}: {message}");
                ChatTextBox.AppendText("\n");
            });

            await _connection.StartAsync();

            await _connection.InvokeAsync("GetKeys");
        }
Beispiel #2
0
        public async Task ReceiveKey(int y)
        {
            var keys = _keys[Context.ConnectionId];

            keys.Key = DiffieHellmanService.GetKey(y, keys.X, keys.Q);
        }