private void SaveConnectDataFile(string EncKey, string PathSettingDataFile, string NameDataFile)
        {
            if (RememberCheck.IsChecked == true)
            {
                string ClearText = "";
                if (ServerAdafruit)
                {
                    ClearText = NickName.Text + "|" + UsernameTxt.Text + "|" + AioKeyTxt.Password;
                }
                else if (ServerSolace)
                {
                    ClearText = SolaceNickName.Text + "|ssl://" + SolaceHostPort.Text + "|" + SolacePassword.Password;
                }

                string EncryptedText = StringCipher.Encrypt(ClearText, EncKey);
                if (!Directory.Exists(PathSettingDataFile))
                {
                    Directory.CreateDirectory(PathSettingDataFile);
                }
                using (StreamWriter ConnectionData = new StreamWriter(PathSettingDataFile + NameDataFile))
                {
                    ConnectionData.WriteLine(EncryptedText);
                }
            }
            else
            {
                if (File.Exists(PathSettingDataFile + NameDataFile))
                {
                    File.Delete(PathSettingDataFile + NameDataFile);
                }
            }
        }
        private async void BtnShare_Click(object sender, RoutedEventArgs e)
        {
            var KeyRoomSelected = selectRoom.Name.Split('_');

            FeedsJson.FeedProprety feedProprety = await getDataJson(KeyRoomSelected[2]);

            var    licenseValue = feedProprety.license.Split('*');
            string KeyRoomDec   = feedProprety.key + "|" + MqttConnection.UserName + "|" + MqttConnection.AioKey + "|" + licenseValue[0] + "|" + MqttConnection.NickName + "|" + licenseValue[1] + "|" + licenseValue[2] + "|" + MqttConnection.MqttServer + "|" + MqttConnection.MqttPort.ToString();
            string KeyRoomEnc   = StringCipher.Encrypt(KeyRoomDec, "");

            Clipboard.SetText(KeyRoomEnc);
            DrawerHost.CloseDrawerCommand.Execute(DrawerHostContent, BtnShare);
            ShowSnackBar("Key room copied in ClipBoard!");
        }
 public static async void MqttPublish(string Topic, string DataMessage)
 {
     DataMessage = StringCipher.Encrypt(DataMessage, Key_EndToEnd);
     await Task.Run(() => client.Publish(Topic, Encoding.UTF8.GetBytes(DataMessage)));
 }
        private async void GenerateBtn_Click(object sender, RoutedEventArgs e)
        {
            if (NameRoom.Text != "" && !string.IsNullOrWhiteSpace(UsernameTxt.Text) && !string.IsNullOrWhiteSpace(AioKeyTxt.Password) && !string.IsNullOrWhiteSpace(Key_EndToEnd.Text) && !Key_EndToEnd.Text.Contains("GENERATE"))
            {
                HttpRequest req = new HttpRequest();

                string KeyRoomDec = req.getCorretName(NameRoom.Text) + "|" + UsernameTxt.Text + "|" + AioKeyTxt.Password + "|" + Key_EndToEnd.Text + "|" + MqttConnection.NickName + "|" + UrlTxt.Text + "|" + CheckControll.IsChecked + "|" + MqttConnection.MqttServer + "|" + MqttConnection.MqttPort.ToString();
                string KeyRoomEnc = StringCipher.Encrypt(KeyRoomDec, "");

                if (CheckCurrentData.IsChecked == true)
                {
                    if (getNumFeed(req.getAllFeeds()) != 10)
                    {
                        MqttConnection.MqttUnsubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                        if (req.createFeed(NameRoom.Text, DescriptionTxt.Text, Key_EndToEnd.Text, UrlTxt.Text, CheckControll.IsChecked.ToString()))
                        {
                            MqttConnection.setKeyEndToEnd(Key_EndToEnd.Text);
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                            MqttConnection.MqttPublish(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey, MqttConnection.NickName + "_ROOMGROUP_" + NameRoom.Text + "_" + UrlTxt.Text);
                            Clipboard.SetText(KeyRoomEnc);
                            MessageBox.Show("Room created!!!" + '\n' + '\n' + "Don't worry, I copy the access key to the group, share it with your friends, you just have to paste and they just have to copy it and click on \"I have a key\"");
                            Close();
                        }
                        else
                        {
                            MqttConnection.setKeyEndToEnd("");
                            MqttConnection.setChatRoomNameKey("chat");
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                            ShowSnackBar("Error creating room!");
                        }
                    }
                    else
                    {
                        ShowSnackBar("Max number of group created, delete one!");
                    }
                }
                else
                {
                    string tempUser   = MqttConnection.UserName;
                    string tempAioKey = MqttConnection.AioKey;
                    MqttConnection.MqttDisconnect();
                    MqttConnection.setUser(UsernameTxt.Text);
                    MqttConnection.setAioKey(AioKeyTxt.Password);
                    if (!(await MqttConnection.MqttFastConnect()))
                    {
                        MqttConnection.setUser(tempUser);
                        MqttConnection.setAioKey(tempAioKey);
                        ShowSnackBar("Erron to connect with new data!");
                        UsernameTxt.Focus();
                        return;
                    }

                    if (getNumFeed(req.getAllFeeds()) != 10)
                    {
                        if (req.createFeed(NameRoom.Text, DescriptionTxt.Text, Key_EndToEnd.Text, UrlTxt.Text, CheckControll.IsChecked.ToString()))
                        {
                            MqttConnection.setKeyEndToEnd(Key_EndToEnd.Text);
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/clients");
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                            MqttConnection.MqttPublish(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey, MqttConnection.NickName + "_ROOMGROUP_" + NameRoom.Text + "_" + UrlTxt.Text);
                            Clipboard.SetText(KeyRoomEnc);
                            MessageBox.Show("Room created!!!" + '\n' + '\n' + "Don't worry, I copy the access key to the group, share it with your friends, you just have to paste and they just have to copy it and click on \"I have a key\"");
                            Close();
                        }
                        else
                        {
                            MqttConnection.setKeyEndToEnd("");
                            MqttConnection.setChatRoomNameKey("chat");
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/clients");
                            MqttConnection.MqttSubscribe(MqttConnection.UserName + "/feeds/" + MqttConnection.ChatRoomNameKey);
                            ShowSnackBar("Error creating room!");
                        }
                    }
                    else
                    {
                        ShowSnackBar("Max number of group created, delete one!");
                    }
                }
            }
            else
            {
                ShowSnackBar("Complete the box please");
            }
        }