/// <summary>
        /// Retreives the master key from isolated storage. If a key does not exist, it will create a new one.
        /// </summary>
        /// <returns></returns>
        public static byte[] GetMasterKey()
        {
            byte[] MasterKey = new byte[0];

            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())
            {
                if (store.FileExists(KeyFileName))
                {
                    // Load the file
                    using (IsolatedStorageFileStream file = store.OpenFile(KeyFileName, FileMode.Open))
                    {
                        MasterKey = new byte[file.Length];
                        file.Read(MasterKey, 0, Convert.ToInt32(file.Length));
                    }
                }
                else
                {
                    // Generate new master key, and save it to a file
                    // The method we generate this does not have to match other platforms, it just has to be random
                    MasterKey = MSPWDCrypto.CreateMasterKey(MSPWDCrypto.CreateRandomString());
                    SetMasterKeyFile(MasterKey);
                }
            }

            return(MasterKey);
        }
Exemple #2
0
 private void GenerateButton_Click(object sender, RoutedEventArgs e)
 {
     if (MSPWDStorage.MasterKeyFileExists())
     {
         txtOutput_Alpha.Text   = MSPWDCrypto.CreatePassword_Alpha(txtInput.Text);
         txtOutput_Special.Text = MSPWDCrypto.CreatePassword_Special(txtInput.Text);
         enableClipboardButtons(true);
     }
     else
     {
         MessageBox.Show("Master key not present - set the master key before generating passwords");
     }
 }
        private void btn_SaveButton_Click(object sender, RoutedEventArgs e)
        {
            string newSalt = txtSaltInput.Text.Trim();

            if (string.IsNullOrEmpty(newSalt))
            {
                // Don't let a short key be set
                MessageBox.Show("Key must be longer than 3 characters", "Key error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                MSPWDStorage.SetMasterKeyFile(MSPWDCrypto.CreateMasterKey(newSalt));
                Close();
            }
        }