Beispiel #1
0
        // Specify user pasword and initialize relative data structure.
        public static bool Initialize(string userPass, bool saveUserPass)
        {
            // Clear saved old data
            ApplicationData.Current.LocalSettings.Values.Clear();

            // Create new master password string
            Random        r          = new Random();
            StringBuilder masterPass = new StringBuilder();

            for (int i = 0; i < 64; i++)
            {
                char c = (char)(r.Next(1, 254) * 8 + r.Next(1, 254));
                masterPass.Append(c);
            }
            string masterPassStr = masterPass.ToString();

            // Save master password string
            ApplicationData.Current.LocalSettings.Values[MASTERPASS_KEYNAME] =
                Crypt.Base64Encoding(Crypt.CipherEncryption(masterPassStr, userPass, false));

            // if user password saving is specified, encrypt user password by fixed string
            if (saveUserPass)
            {
                SaveUserPassword(userPass);
            }

            // Create empty current file.
            PasswordFile pf = new PasswordFile();

            return(Save(masterPassStr, pf.BuildStringForOutput(false)));
        }
Beispiel #2
0
        /// <summary>
        /// Export password file button is clicked.
        /// </summary>
        private async void ExportPasswordFileButton_Click(object sender, RoutedEventArgs e)
        {
            _ = sender;
            _ = e;

            // Load selected password file. If not selected ignore this event
            var r = await LoadSelectedPasswordFile().ConfigureAwait(true);

            PasswordFile pwfile   = r.Item1;
            string       password = r.Item2;

            if (string.IsNullOrEmpty(password) || null == pwfile)
            {
                return;
            }

            // Get output path name of a new plain text file
            FileSavePicker p = new FileSavePicker();

            p.FileTypeChoices.Add(GlbFunc.GetResourceString("TextFileTypeDescription", "Text File"), new List <string>()
            {
                ".txt"
            });
            p.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            StorageFile txtFile = await p.PickSaveFileAsync();

            if (null == txtFile)
            {
                return;
            }

            // Generate string for output
            string plainText = pwfile.BuildStringForOutput(true);

            // write plain text file
            await FileIO.WriteBufferAsync(txtFile, Encoding.GetEncoding( "UTF-8" ).GetBytes( plainText ).AsBuffer());
        }