public UDPControl()
 {
     this.InitializeComponent();
     app.keyPair = CryptoClass.generateSessionKey();
     sessionKey  = CryptoClass.getPreGeneratedPublicKey(app.keyPair);
     initSocket();
     t.Interval = TimeSpan.FromSeconds(1);
     t.Tick    += T_Tick;
 }
        private void sendMbed()
        {
            string sendString = "$" + CryptoClass.AES_Ecrypt(app.s, app.passAES);

            sendData(app.partIP, sendString);
            showText.Text = "your IP" + app.localIP + "\npartner's IP"
                            + app.partIP + "\nPartner's Key:"
                            + app.passAESPart + "\n" + "LocalKey:" + app.passAES + "\n" + "You've sent " + i + " times";
        }
        private void getBtn_Click(object sender, RoutedEventArgs e)
        {
            app.passAES   = CryptoClass.GenerateRandomString();
            showText.Text = "your IP" + app.localIP + "\npartner's Ip" + app.partIP
                            + "\nPartner's Key:"
                            + app.passAESPart + "\n" + "LocalKey:" + app.passAES;
            string sendString = "@" + CryptoClass.RSA_Encrypt(app.passAES, app.publicKey);

            sendData(app.partIP, sendString);
        }
        private async void SocketLister_ConnectionRecevived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            //listen the port
            Stream inStream = args.Socket.InputStream.AsStreamForRead();
            //data got
            StreamReader reader    = new StreamReader(inStream);
            string       getString = await reader.ReadLineAsync();

            if (getString.Contains("@"))
            {
                app.passAESPart = CryptoClass.RSA_Decrypt(getString.Substring(1), app.keyPair);
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, (() =>
                {
                    showText.Text = "your IP" + app.localIP + "\npartner's Ip" + app.partIP + "\nPartner's Key:" + app.passAESPart + "\n" + "LocalKey:" + app.passAES;
                }));
            }
            else if (getString.Contains("$"))
            {
                string getOString = CryptoClass.AES_Decrypt(getString.Substring(1), app.passAESPart);

                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, (() =>
                {
                    try
                    {
                        getText.Text = getOString;
                        string[] strInput = getOString.Split(',');
                        tempText.Text = strInput[0];
                        port1Text.Text = strInput[1];
                        port2Text.Text = strInput[2];
                        xText.Text = strInput[3];
                        yText.Text = strInput[4];
                        zText.Text = strInput[5];
                    }
                    catch (Exception)
                    {
                    }
                }));
            }

            //put message to UI
        }