コード例 #1
0
        /// <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.GetUserStoreForApplication())
            {
                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);
        }
コード例 #2
0
        private void btnSetMasterKey_Click(object sender, RoutedEventArgs e)
        {
            string newKeyText = txtNewMasterKey.Text.Trim();

            if ((string.IsNullOrEmpty(newKeyText)) || (newKeyText.Length < 3))
            {
                MessageBox.Show("ERROR: Master key not long enough. Key must be longer than 3 characters");
            }
            else
            {
                MSPWDStorage.SetMasterKeyFile(MSPWDCrypto.CreateMasterKey(txtNewMasterKey.Text.Trim()));
                txtNewMasterKey.Text = string.Empty;

                // Add the "delete master key" page back
                if (!pvtPages.Items.Contains(tabSpecial))
                {
                    pvtPages.Items.Add(tabSpecial);
                }
                if (!pvtPages.Items.Contains(tabAlpha))
                {
                    pvtPages.Items.Add(tabAlpha);
                }
                if (!pvtPages.Items.Contains(tabClean))
                {
                    pvtPages.Items.Add(tabClean);
                }

                pvtPages.SelectedItem = tabSpecial;
            }
        }