public static async Task <String> GetPasswords(CryptographicKey AesKey)
        {
            CryptographicKey k = await GetRasKey(AesKey);

            String R = "";

            try
            {
                int a = int.Parse(await StorageInterface.ReadFromRoamingFolder("PWM/INDEX"));
                for (int i = 0; i < a; i++)
                {
                    IBuffer crypitic = await StorageInterface.ReadBufferFromRoamingFolder("PWM/Passwords" + i);

                    IBuffer plain = DecryptRsa(k, crypitic);
                    String  X     = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, plain);
                    if (X == null)
                    {
                        X = "";
                    }
                    R += X;
                }
            }
            catch (Exception e)
            {
                e.PrintStackTrace();
                return("");
            }
            return(R);
        }
        public static async Task InitialSetup(CryptographicKey AesKey)
        {
            StoreRsaKey(GenerateRsaKey(), AesKey);
            await StorageInterface.WriteToRoamingFolder("PWM/Passwords0", "");

            await StorageInterface.WriteToRoamingFolder("PWM/INDEX", "1");
        }
Exemple #3
0
        public void PrintSensors(bool fast = false)
        {
            //BarometerReading read = baro.GetCurrentReading();
            var accR = acc.GetCurrentReading();
            //Debug.WriteLine(Math.Sqrt(Math.Pow(accR.AccelerationX; 2) + Math.Pow(accR.AccelerationY; 2) + Math.Pow(accR.AccelerationZ; 2)) + " (" + accR.AccelerationX + "/" + accR.AccelerationX + "/" + accR.AccelerationX + ")");
            //var actR = act.GetCurrentReadingAsync().GetResults();
            //Debug.WriteLine(actR.Activity + " (" + actR.Confidence + ")");
            //Debug.WriteLine(alt.GetCurrentReading().AltitudeChangeInMeters);
            //Debug.WriteLine(baro.GetCurrentReading().StationPressureInHectopascals);
            var compR = comp.GetCurrentReading();
            //Debug.WriteLine(compR.HeadingMagneticNorth + " (+/-" + compR.HeadingAccuracy + ")");
            var gyroR = gyro.GetCurrentReading();
            //Debug.WriteLine("(" + gyroR.AngularVelocityX + "/" + gyroR.AngularVelocityY + "/" + gyroR.AngularVelocityZ + ")");
            var incR = inc.GetCurrentReading();
            //Debug.WriteLine("(" + incR.PitchDegrees + "/" + incR.RollDegrees + "/" + incR.YawDegrees + ")");
            //var psR=ps.GetCurrentReading();
            //Debug.WriteLine(psR.IsDetected + ": " + psR.DistanceInMillimeters);
            //Debug.WriteLine(sos.GetCurrentOrientation());



            String csv = (Math.Sqrt(Math.Pow(accR.AccelerationX, 2) + Math.Pow(accR.AccelerationY, 2) + Math.Pow(accR.AccelerationZ, 2)) + ";" + accR.AccelerationX + ";" + accR.AccelerationY + ";" + accR.AccelerationZ + ";"
                          + alt.GetCurrentReading().AltitudeChangeInMeters + ";" + baro.GetCurrentReading().StationPressureInHectopascals + ";" + compR.HeadingMagneticNorth + ";" + compR.HeadingTrueNorth + ";" + compR.HeadingAccuracy
                          + ";" + gyroR.AngularVelocityX + ";" + gyroR.AngularVelocityY + ";" + gyroR.AngularVelocityZ + ";" + incR.PitchDegrees + ";" + incR.RollDegrees + ";" + incR.YawDegrees + ";" + sos.GetCurrentOrientation() + ";" + accR.Timestamp.ToUnixTimeMilliseconds() + ";" + fast);

            Debug.WriteLine(csv);
            StorageInterface.AppendToKnownStorageFile(Token, csv + "\r\n").GetAwaiter();
            OUT.Text += csv + "\r\n";
        }
        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();
        }
Exemple #5
0
        private async void ExportAllButton_Click(object sender, RoutedEventArgs e)
        {
            String Token = await StorageInterface.PickExternalStorageFolder();

            StorageFolder target = await StorageInterface.GetStorageFolderFromToken(Token);

            target = await target.CreateFolderAsync(SourceFolder.Name, CreationCollisionOption.OpenIfExists);

            if (MultiSelect)
            {
                for (int i = 0; i < Files.Length; i++)
                {
                    if (SelectItems[i].IsChecked == true)
                    {
                        await Files[i].CopyAsync(target, Files[i].Name, NameCollisionOption.ReplaceExisting);
                    }
                }
                for (int i = 0; i < Folders.Length; i++)
                {
                    if (FSelect[i].IsChecked == true)
                    {
                        await Folders[i].CopyFolderContentsTo(await target.CreateFolderAsync(Folders[i].Name, CreationCollisionOption.GenerateUniqueName));
                    }
                }
            }
            else
            {
                await SourceFolder.CopyFolderContentsTo(target);
            }
            DeactivateMultiSelect();
        }
Exemple #6
0
 private async Task Download()
 {
     ServerInterface.ServerPacket sp = ServerInterface.ReadFile("/home/aio/AIO/ToDo.list");
     if (sp.Flags[1] == ServerInterface.ACK)
     {
         await StorageInterface.WriteBytesToLocalFolder("ToDo.list", sp.Message);
     }
 }
Exemple #7
0
        private async void Sample_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Token = await StorageInterface.PickExternalStorageFile_NewFile("log.txt");

            await StorageInterface.WriteToKnownStorageFile(Token, "acc;accX;accY;accZ;alt;baro;compMN;compTN;compAC;gyroX;gyroY;gyroZ;pitch;roll;yaw;sos;ts(acc);isFast\r\n");

            UserInteraction.ShowToast("Sensors", "INIT DONE!");
        }
Exemple #8
0
        private async void SelectFolderButton_Click(object sender, RoutedEventArgs e)
        {
            i = 0;
            bool x = halted;

            halted = true;
            arr    = await(await StorageInterface.GetStorageFolderFromToken(await StorageInterface.PickExternalStorageFolder())).GetStorageFileArray();
            Show();
            PauseButton.IsEnabled = true;
            halted = x;
        }
Exemple #9
0
        private async void StoreNewEntry(object sender, RoutedEventArgs e)
        {
            newEditOk.Click -= StoreNewEntry;
            newDelete.Click -= CancelNewEntry;
            cumulatedData    = await StorageInterface.ReadFromLocalFolder("ToDo.list");

            cumulatedData = newOverview.Text + INTRASPLIT + newDetails.Text + INTERSPLIT + cumulatedData;
            await StorageInterface.WriteToLocalFolder("ToDo.list", cumulatedData);

            await Upload();
            await Refresh();
        }
Exemple #10
0
        public static async Task LoadAll()
        {
            String log = await StorageInterface.ReadFromRoamingFolder("BMW/log.log");

            String cfg = await StorageInterface.ReadFromRoamingFolder("BMW/cfg.cfg");

            String[] cfgs = cfg.Split("|");
            if (cfgs[0].Equals("IN"))
            {
                checkedIn = true;
            }
            msSinceEpoch = long.Parse(cfgs[1]);
        }
Exemple #11
0
        private async void FolderSave_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < Folders.Length; i++)
            {
                if (sender == FSave[i])
                {
                    String Token = await StorageInterface.PickExternalStorageFolder();

                    await Folders[i].CopyFolderContentsTo(await(await StorageInterface.GetStorageFolderFromToken(Token)).CreateFolderAsync(Folders[i].Name, CreationCollisionOption.GenerateUniqueName));
                    //await Files[i].CopyAndReplaceAsync(await StorageInterface.GetStorageFileFromToken(Token));
                }
            }
        }
        private async void TestServer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Debug.WriteLine(await ClintServerMethods.SendDataAndRecieveAnswer("localhost", 1337, "TEST REQUEST"));
                await ServerInterface.UploadFile(await StorageInterface.GetStorageFileFromToken(await StorageInterface.PickExternalStorageFile_OpenFile()), "/CODE/IMG.png");// "C:\\Users\\alder\\Desktop\\IMG.png", "localhost");

                //ServerInterface.ReadFile("invalidTestFile");//if reading a non-existent file I get 0x15 (NAK) in flags[1]
            }
            catch (Exception ex)
            {
                ex.PrintStackTrace();
            }
        }
Exemple #13
0
        private async void AddFileButton_Click(object sender, RoutedEventArgs e)
        {
            DeactivateMultiSelect();
            String[] Token = await StorageInterface.PickExternalStorageFiles_OpenFiles();

            for (int i = 0; i < Token.Length; i++)
            {
                StorageFile file = await StorageInterface.GetStorageFileFromToken(Token[i]);

                await file.CopyAsync(SourceFolder, file.Name, NameCollisionOption.ReplaceExisting);
            }
            Files = await SourceFolder.GetStorageFileArray();

            ReLoadPage();
        }
Exemple #14
0
        async Task Nav()
        {
            if (i < 0)
            {
                i = 0;
            }
            ComicImage.Source = await StorageInterface.GetImageSourceFromStorageFile(arr[i++]);

            if (i == arr.Length)
            {
                i      = 0;
                halted = true;
                PauseButton.Content    = "ENDE. Neu starten?";
                PauseButton.Background = new SolidColorBrush(Colors.Red);
            }
        }
        public static async Task <Boolean> IsInitial()
        {
            String x;

            try
            {
                x = await StorageInterface.ReadFromRoamingFolder("PWM/Passwords0");
            }
            catch (ArgumentOutOfRangeException EX) //Non-Unicode zeichen in dem verschlüsselten text können nicht richtig interpretiert werden, das heist aber, dass die Datei existiert und schon was drinsteht => reicht aus für diese überprüfung
            {
                x = EX.Message;                    //Eigentlicher inhalt der datei wird durch einen garantiert korrekten String ersetzt, falls die ursprüngliche nachricht nicht als String gelesen werden kann.
                EX.PrintStackTrace();
            }
            Debug.WriteLine("HAVE READ");
            bool X = (x == null || x.Equals("")) ? true : false;//falls entweder irgendwas in der datei steht oder die datei zeichen enthält die nicht gelesen werden können (d.h. die date nicht leer ist true sonst false;)

            Debug.WriteLine(X);
            return(X);
        }
Exemple #16
0
        private async void ExportSingleFile(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < Files.Length; i++)
            {
                if (sender == ExportButton[i])
                {
                    String Token = await StorageInterface.PickExternalStorageFile_NewFile(Files[i].DisplayName);

                    try
                    {
                        await Files[i].CopyAndReplaceAsync(await StorageInterface.GetStorageFileFromToken(Token));
                    }
                    catch (Exception ex)
                    {
                        ex.PrintStackTrace();
                    }
                }
            }
        }
        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();
        }
        public static async Task StorePasswords(String Passwords, CryptographicKey AesKey)
        {
            CryptographicKey k = await GetRasKey(AesKey);

            int a = int.Parse(await StorageInterface.ReadFromRoamingFolder("PWM/INDEX"));

            for (int i = 0; i < a; i++)
            {
                await StorageInterface.DeleteFromRoamingFolder("PWM/Passwords" + i);
            }


            String[] PWD = Passwords.DivideToLength(768);
            await StorageInterface.WriteToRoamingFolder("PWM/INDEX", PWD.Length.ToString());

            for (int i = 0; i < PWD.Length; i++)
            {
                IBuffer plain   = CryptographicBuffer.ConvertStringToBinary(PWD[i], BinaryStringEncoding.Utf8);
                IBuffer cryptic = CryptographicEngine.Encrypt(k, plain, null);
                await StorageInterface.WriteBufferToRoamingFolder("PWM/Passwords" + i, cryptic);
            }
        }
Exemple #19
0
        private async Task Refresh()
        {
            String[] X = (await StorageInterface.ReadFromRoamingFolder("PoloTanken.csv")).Trim().Replace("\r", "|").Replace("\n", "|").Split("|");
            Double   km = 0, cost = 0, liter = 0;

            foreach (String A in X)
            {
                String[] S = A.Trim().Split(";");
                km    += Double.Parse(S[0]);
                liter += Double.Parse(S[1]);
                cost  += Double.Parse(S[2]);
            }
            TotalKmBox.Text    = km.ToString();
            TotalEuroBox.Text  = cost.ToString();
            TotalLiterBox.Text = liter.ToString();
            TotalAvgBox.Text   = (100 * liter / km).ToString();

            DateTime start     = new DateTime(2019, 11, 6, 15, 0, 0);
            DateTime now       = DateTime.Now;
            TimeSpan diff      = now - start;
            double   allowedKm = (KM * 12.0 * diff.TotalSeconds) / (24 * 3600 * MONTHS * 365.25);

            maxKmBox.Text = allowedKm.ToString();
        }
Exemple #20
0
        private async void Download()
        {
            String Token = await StorageInterface.ReadFromLocalFolder("Storage.Garfield.token");

            if (Token == null || Token.Equals(""))
            {
                await UserInteraction.ShowDialogAsync("INFORMATION", "You will now be prompted to chose a Folder in which to save the Comic. This App will create a new Folder within the Folder you selected, called \"Garfield\", which will be used to store the images (in order not to confuse them with your files). The App will remember the location you have picked and will use this location until you change it in the Settings.");

                Token = await StorageInterface.PickExternalStorageFolder();

                await StorageInterface.WriteToLocalFolder("Storage.Garfield.token", Token);
            }
            try
            {
                await StorageInterface.WriteBytesToKnownFolder("Garfield/Garfield_" + date.ToString("yyyy_MM_dd") + ".gif", await NetworkInterface.DownloadGarfield(date), Token);
            }
            catch (Exception e)
            {
                e.PrintStackTrace();
                UserInteraction.ShowToast("ERROR! Could not save file.", "Garfield");
                return;
            }
            UserInteraction.ShowToast("Comic has successfully been saved", "Garfield");
        }
Exemple #21
0
        private async Task SaveCurrentContents()
        {
            String contentsToSTore = "";

            for (int i = 0; i < index; i++)
            {
                try
                {
                    if (overview[i].Text.Equals("") && details[i].Text.Equals(""))
                    {
                        continue;
                    }
                    contentsToSTore += overview[i].Text + INTRASPLIT + details[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
                }
            }
            await StorageInterface.WriteToLocalFolder("ToDo.list", contentsToSTore);

            await Upload();
            await Refresh();
        }
Exemple #22
0
        private async void AddEntryButton_Click(object sender, RoutedEventArgs e)
        {
            await StorageInterface.WriteToRoamingFolder("PoloTanken.csv", await StorageInterface.ReadFromRoamingFolder("PoloTanken.csv") + "\r\n" + await InputTextDialogAsync("Neue Batankung"));

            await Refresh();
        }
 private static async void StoreRsaKey(CryptographicKey key, CryptographicKey aesKey)
 {
     await StorageInterface.WriteBufferToRoamingFolder("PWM/RsaKey", EncryptAes(aesKey, key.Export()));
 }
 private static async Task <CryptographicKey> GetRasKey(CryptographicKey AesKey)
 {
     return(AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaPkcs1).ImportKeyPair(DecryptAes(AesKey, await StorageInterface.ReadBufferFromRoamingFolder("PWM/RsaKey"))));
 }
Exemple #25
0
 private async Task Upload()
 {
     await ServerInterface.UploadFile(await StorageInterface.GetStorageFileFromLocalStorage("ToDo.list"), "/home/aio/AIO/ToDo.list");
 }
Exemple #26
0
        private async Task Refresh()
        {
            Stack.Children.Clear();
            Init();
            await Download();

            cumulatedData = await StorageInterface.ReadFromLocalFolder("ToDo.list");

            if (cumulatedData == null)
            {
                await StorageInterface.WriteToLocalFolder("ToDo.list", "");
                await Upload();
            }
            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];
            details    = 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].EndsWith(INTRASPLIT))
                {
                    entries[i] += " ";
                }
                String[] X = entries[i].Split(INTRASPLIT);

                /*for(int j = 0; j < X.Length; j++)
                 * {
                 *  if (X[j].Equals(""))
                 *  {
                 *      X[j] = " ";
                 *  }
                 * }*/



                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]
                };

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

                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(details[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;
            }
        }