public void _clientHandler_InitiateNegotiation(object sender, InitiateNegotiationEventArgs e)
        {
            try
            {
                foreach (IMLibrary.Client client in e.ClientList)
                {
                    if (GeneratedClientList.Count(cli => cli.UserName == client.UserName) == 0)
                    {
                        //generate a new key/salt pair with the correct public key and negotiate with the client
                        Tuple <byte[], byte[]> unencryptedKeySaltPair = GenerateUnencryptedKeySaltPair();
                        Tuple <byte[], byte[]> encryptedKeySalePair   = EncryptKeySaltPair(client.PublicKey, unencryptedKeySaltPair);
                        _clientHandler.NegotiateSymmetricKeys(encryptedKeySalePair, client.UserName);

                        if (this._clientKeyIvDictionary.ContainsKey(client.UserName))
                        {
                            this._clientKeyIvDictionary.Remove(client.UserName);
                        }
                        this._clientKeyIvDictionary.Add(client.UserName, unencryptedKeySaltPair);
                    }
                }
            }
            catch
            {
            }
        }
        public ImMainWindowNew(ImClientHandler clientHandler)
        {
            InitializeComponent();
            _clientHandler = clientHandler;

            GeneratedClientList = new ObservableCollection <User>();
            foreach (IMLibrary.Client client in _clientHandler.GeneratedClientList)
            {
                GeneratedClientList.Add(new User(client.UserName, client.Available, client.FingerPrint, client.PublicKey, client.Buddies, 0));
            }

            //GeneratedClientList.CollectionChanged += GeneratedClientList_CollectionChanged;

            _clientHandler.ListEventHandler           += _clientHandler_ListEventHandler;
            _clientHandler.KeyNegotiationEventHandler += _clientHandler_KeyNegotiationEventHandler;
            _clientHandler.NegotiationEventHandler    += _clientHandler_InitiateNegotiation;
            _clientHandler.BuddyEventHandler          += _clientHandler_BuddyEventHandler;
            _filteredView = new CollectionViewSource {
                Source = GeneratedClientList
            }.View;

            DataContext = new
            {
                user    = _clientHandler.ClientInfo,
                clients = _filteredView,
                //messages = _clientMessagesReceivedTupleList
            };
            _filteredView.Refresh();
            IMChatPromtEventHandler chatPromtEventHandler = MessageReceiveHandler;

            clientHandler.ChatPromtCheck += chatPromtEventHandler;

            foreach (User client in GeneratedClientList)
            {
                ChatDialogueLocal chatDialogoue = new ChatDialogueLocal {
                    lblUsername = { Content = client.UserName }, lblFingerPrint = { Content = client.FingerPrint }
                };
                chatDialogoue.ButtonRegenerateKeys.Click += ButtonRegenerateKeys_Click;
                _clientPromtList.Add(new Tuple <IMLibrary.Client, ChatDialogueLocal>(client, chatDialogoue));
                //_clientMessagesReceivedTupleList.Add(new Pair<IMLibrary.Client, string>(client, "0"));
                if (client.FingerPrint != null)
                {
                    chatDialogoue.ChangeColourOfPrint();
                    chatDialogoue.LoadPrint();

                    //new instant of aes, key and IV are created and access through properties. f
                    try
                    {
                        Tuple <byte[], byte[]> unencryptedKeySaltPair = GenerateUnencryptedKeySaltPair();
                        Tuple <byte[], byte[]> encryptedKeySaltPair   = EncryptKeySaltPair(client.PublicKey, unencryptedKeySaltPair);

                        if (client.UserName != _clientHandler.ClientInfo.UserName)
                        {
                            _clientHandler.NegotiateSymmetricKeys(encryptedKeySaltPair, client.UserName);
                        }

                        this._clientKeyIvDictionary.Add(client.UserName, unencryptedKeySaltPair);
                    }
                    catch (Exception e)
                    {
                        //will fail if we don't know the clients public key
                    }
                }
            }
        }