private async void Test_Click(object sender, RoutedEventArgs e)
        {
            String Passwords = await CryptoInterface.GetPasswords(Key);

            Debug.WriteLine("<passwords>");
            Debug.WriteLine(Passwords);
            Debug.WriteLine("</passwords>");
            Passwords += "LINE1" + INTRASPLIT + "LINE2" + INTRASPLIT + "LINE3" + INTERSPLIT;
            Debug.WriteLine("ALTERED PASSWORDS");
            Debug.WriteLine("<passwords>");
            Debug.WriteLine(Passwords);
            Debug.WriteLine("</passwords>");
            await CryptoInterface.StorePasswords(Passwords, Key);

            Debug.WriteLine("WROTE NEW PASSWORDS");
            Passwords = "";
            Debug.WriteLine("<clearedPasswords>");
            Debug.WriteLine(Passwords);
            Debug.WriteLine("</clearedPasswords>");
            Passwords = await CryptoInterface.GetPasswords(Key);

            Debug.WriteLine("READ NEW PASSWORDS");
            Debug.WriteLine("<passwords>");
            Debug.WriteLine(Passwords);
            Debug.WriteLine("</passwords>");
        }
        private async Task Logon()
        {
            Key = CryptoInterface.GestAesKey(LoginPasswordBox.Password);
            LoginPasswordBox.Password = "";
            IBuffer A = await StorageInterface.ReadBufferFromRoamingFolder("PWM/A");

            IBuffer B = await StorageInterface.ReadBufferFromRoamingFolder("PWM/B");

            //Debug.WriteLine("Up to here I believe this to be OK");
            //Debug.WriteLine(LoginPasswordBox.Password.GetHexString());
            //Debug.WriteLine(Key);
            IBuffer EA = CryptoInterface.EncryptAes(Key, A);

            //Debug.WriteLine("Now this could be unreachable code");
            if (!CryptographicBuffer.Compare(B, EA))//Falsches Passwort, da die testfiles nicht zampassen
            {
                Debug.WriteLine("FALSCHES PASSWORT");
                await UserInteraction.ShowDialogAsync("INFORMATION", "Falsches Passwort!");

                return;
            }
            Debug.WriteLine("HAVE DONE SETUP WITH PASSWORD");
            MODE_REGULAR.Visibility = MODE_REGULAR_BAR.Visibility = Visibility.Visible;
            MODE_LOGIN.Visibility   = MODE_SETUP.Visibility = Visibility.Collapsed;
            await Refresh();
        }
 private async void Setup()
 {
     Key = null;
     if (await CryptoInterface.IsInitial())
     {
         Debug.WriteLine("INITIAL STATE DETECTED");
         MODE_SETUP.Visibility = Visibility.Visible;
         MODE_LOGIN.Visibility = MODE_REGULAR.Visibility = MODE_REGULAR_BAR.Visibility = Visibility.Collapsed;
     }
     else
     {
         Debug.WriteLine("NOT INITIAL STATE DETECTED");
         MODE_LOGIN.Visibility = Visibility.Visible;
         MODE_SETUP.Visibility = MODE_REGULAR.Visibility = MODE_REGULAR_BAR.Visibility = Visibility.Collapsed;
     }
     LoginPasswordBox.KeyDown += LoginPasswordBox_KeyDown;
 }
        private async void InitialSetupButton_Click(object sender, RoutedEventArgs e)
        {
            String PWD = SetupAPasswordBox.Password;

            Debug.WriteLine(PWD);
            Key = CryptoInterface.GestAesKey(PWD);
            IBuffer X = CryptoInterface.CreateTestfile();
            await StorageInterface.WriteBufferToRoamingFolder("PWM/A", X);

            await StorageInterface.WriteBufferToRoamingFolder("PWM/B", CryptoInterface.EncryptAes(Key, X));

            await CryptoInterface.InitialSetup(Key);

            await CryptoInterface.StorePasswords("Dieser Passwortmanager" + INTRASPLIT + "Kein Benutzername" + INTRASPLIT + PWD + INTERSPLIT, Key);

            Debug.WriteLine("HAVE DONE SETUP WITH PASSWORD");
            MODE_REGULAR.Visibility = MODE_REGULAR_BAR.Visibility = Visibility.Visible;
            MODE_LOGIN.Visibility   = MODE_SETUP.Visibility = Visibility.Collapsed;
            await Refresh();
        }
        private async void StoreNewEntry(object sender, RoutedEventArgs e)
        {
            newEditOk.Click -= StoreNewEntry;
            newDelete.Click -= CancelNewEntry;
            String cumulatedData = await CryptoInterface.GetPasswords(Key);

            if (newUsername.Text.Equals(""))
            {
                newUsername.Text = "Kein Benutzername";
            }
            if (newPassword.Text.Equals(""))
            {
                newPassword.Text = "Kein Passwort";
            }
            if (newOverview.Text.Equals(""))
            {
                newOverview.Text = "Kein Name";
            }
            cumulatedData = newOverview.Text + INTRASPLIT + newUsername.Text + INTRASPLIT + newPassword.Text + INTERSPLIT + cumulatedData;
            await CryptoInterface.StorePasswords(cumulatedData, Key);

            await Refresh();
        }
        private async Task SaveCurrentContents()
        {
            String contentsToSTore = "";

            for (int i = 0; i < index; i++)
            {
                try
                {
                    if (overview[i].Text.Equals("") && username[i].Text.Equals("") && password[i].Text.Equals(""))
                    {
                        continue;//alle felder leer => wurde gelöscht
                    }
                    if (overview[i].Text.Equals(""))
                    {
                        overview[i].Text = "Kein Name";
                    }
                    if (username[i].Text.Equals(""))
                    {
                        username[i].Text = "Kein Benutzername";
                    }
                    if (password[i].Text.Equals(""))
                    {
                        password[i].Text = "Kein Passwort";
                    }
                    contentsToSTore += overview[i].Text + INTRASPLIT + username[i].Text + INTRASPLIT + password[i].Text + INTERSPLIT;
                }
                catch
                {
                    //DO NOTHING THE EXCEPTION PROBABLY HAS BEEN CAUSED BECAUSE THERE WAS NO DATA SO THE REFRESH METHOD JUST SKIPPED THIS DATASET
                }
            }
            if (!contentsToSTore.Equals(""))
            {
                await CryptoInterface.StorePasswords(contentsToSTore, Key);
            }
            await Refresh();
        }
        private async Task Refresh()
        {
            Stack.Children.Clear();
            Init();

            String cumulatedData = await CryptoInterface.GetPasswords(Key);

            String[] entries = cumulatedData.Split(INTERSPLIT);

            index = entries.Length;

            border     = new Border[index];
            grid       = new Grid[index];
            left       = new ColumnDefinition[index];
            right      = new ColumnDefinition[index];
            leftPanel  = new StackPanel[index];
            overview   = new TextBox[index];
            username   = new TextBox[index];
            password   = new TextBox[index];
            rightPanel = new StackPanel[index];
            delete     = new AppBarButton[index];
            editOk     = new AppBarButton[index];
            isEditing  = new Boolean[index];

            for (int i = 0; i < index; i++)
            {
                if (entries[i].Equals(""))
                {
                    continue;
                }
                if (!entries[i].Contains(INTRASPLIT))
                {
                    entries[i] += INTRASPLIT + " ";
                }
                if (!(entries[i].Substring(INTRASPLIT.Length + entries[i].IndexOf(INTRASPLIT)).Contains(INTRASPLIT)))
                {
                    entries[i] += INTRASPLIT + " ";
                }
                String[] X = entries[i].Split(INTRASPLIT);



                border[i] = new Border()
                {
                    BorderThickness = new Thickness(2),
                    BorderBrush     = new SolidColorBrush(Colors.LightGray),
                    CornerRadius    = new CornerRadius(15),
                    Padding         = new Thickness(5),
                    Margin          = new Thickness(5)
                };

                grid[i] = new Grid();

                left[i] = new ColumnDefinition();

                right[i] = new ColumnDefinition()
                {
                    Width = GridLength.Auto
                };

                leftPanel[i] = new StackPanel();

                overview[i] = new TextBox()
                {
                    IsHitTestVisible = false,
                    IsReadOnly       = true,
                    FontSize         = 20,
                    //BorderThickness = new Thickness(0),
                    Text = X[0]
                };

                username[i] = new TextBox()
                {
                    IsHitTestVisible = false,
                    AcceptsReturn    = true,
                    TextWrapping     = TextWrapping.Wrap,
                    Text             = X[1]
                };

                password[i] = new TextBox()
                {
                    IsHitTestVisible = true,
                    AcceptsReturn    = true,
                    TextWrapping     = TextWrapping.Wrap,
                    Text             = X[2]
                };

                rightPanel[i] = new StackPanel();

                delete[i] = new AppBarButton()
                {
                    Icon    = new SymbolIcon(Symbol.Delete),
                    Content = "Erledigt"
                };

                editOk[i] = new AppBarButton()
                {
                    Icon    = new SymbolIcon(Symbol.Edit),
                    Content = "Bearbeiten"
                };

                Stack.Children.Add(border[i]);

                border[i].Child = grid[i];

                grid[i].ColumnDefinitions.Add(left[i]);
                grid[i].ColumnDefinitions.Add(right[i]);

                grid[i].Children.Add(leftPanel[i]);

                leftPanel[i].Children.Add(overview[i]);
                leftPanel[i].Children.Add(username[i]);
                leftPanel[i].Children.Add(password[i]);
                leftPanel[i].SetValue(Grid.ColumnProperty, 0);

                grid[i].Children.Add(rightPanel[i]);

                rightPanel[i].Children.Add(delete[i]);
                rightPanel[i].Children.Add(editOk[i]);
                rightPanel[i].SetValue(Grid.ColumnProperty, 1);

                delete[i].Click += Delete_Click;

                editOk[i].Click += EditOk_Click;
            }
        }