Пример #1
0
 private void _Load_Click(object sender, EventArgs e)
 {
     if (comboBox1.Text == "")
     {
         MessageBox.Show("You Must Select a File to load.  Press Cancel if you wish to return");
         return;
     }
     else
     {
         Fchosen = comboBox1.Text;
         PasswordForm p = new PasswordForm();
         p.Chosen   = Fchosen;
         p.savethis = 1;
         p.ShowDialog();
         if (p.DialogResult == DialogResult.OK)
         {
             pw           = p.Password;
             DialogResult = DialogResult.OK;
             Close();
         }
     }
 }
Пример #2
0
        private void FileSaveAs_Click(object sender, EventArgs e)
        {
            SaveFileDialog d   = new SaveFileDialog();
            string         exe = Assembly.GetExecutingAssembly().Location;

            d.InitialDirectory = Path.GetDirectoryName(exe);
            d.RestoreDirectory = true;
            d.Filter           = "KeyChain Files|*.kcf";
            if (d.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }
            else
            {
                PasswordForm s = new PasswordForm();
                s.ShowDialog();
                string newpass = s.Password;
                if (s.DialogResult != DialogResult.OK)
                {
                    return;
                }
                KeyChainManager.isNamed = d.FileName;
                MemoryStream memoryStream = new MemoryStream();
                Text = d.FileName;
                KeyChainManager.KeyChain.IsModified = false;
                DataContractSerializer dcs = new DataContractSerializer(typeof(KeyChain));
                dcs.WriteObject(memoryStream, KeyChainManager.KeyChain);
                Byte[] ToWrite = CryptoHelper.Encrypt(memoryStream.ToArray(), newpass);
                File.WriteAllBytes(d.FileName, ToWrite);
                memoryStream.Close();

                //commented out for demo
                //DropNetClient Dropbox;
                //add tokens and keys in next line to use dropbox.  Deleted for demo
                //Dropbox = new DropNetClient();
                //Dropbox.UseSandbox = true;
                //var uploaded = Dropbox.UploadFile("/", Path.GetFileName(d.FileName), ToWrite);
            }
        }
Пример #3
0
        public void Save()
        {
            if (KeyChainManager.isNamed != String.Empty)
            {
                PasswordForm s = new PasswordForm();
                s.ShowDialog();
                string newpass = s.Password;
                if (s.DialogResult != DialogResult.OK)
                {
                    return;
                }
                KeyChain d = KeyChainManager.KeyChain;
                if (File.Exists(d.Name))
                {
                    File.Delete(d.Name);
                }


                MemoryStream memoryStream = new MemoryStream();
                KeyChainManager.KeyChain.IsModified = false;
                DataContractSerializer dcs = new DataContractSerializer(typeof(KeyChain));
                dcs.WriteObject(memoryStream, KeyChainManager.KeyChain);
                Byte[] ToWrite = CryptoHelper.Encrypt(memoryStream.ToArray(), newpass);
                File.WriteAllBytes(d.Name, ToWrite);
                memoryStream.Close();

                //Disabled for demo. uncomment to use
                //DropNetClient Dropbox;
                //nextline needs tokens and keys to get dropbox working. Disabled for demo
                //Dropbox = new DropNetClient();
                //Dropbox.UseSandbox = true;
                //var uploaded = Dropbox.UploadFile("/", Path.GetFileName(d.Name), ToWrite);
            }
            else
            {
                SaveFileDialog d   = new SaveFileDialog();
                string         exe = Assembly.GetExecutingAssembly().Location;
                d.InitialDirectory = Path.GetDirectoryName(exe);
                d.RestoreDirectory = true;
                d.Filter           = "KeyChain Files|*.kcf";
                if (d.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
                else
                {
                    PasswordForm s = new PasswordForm();
                    s.ShowDialog();
                    string newpass = s.Password;
                    if (s.DialogResult != DialogResult.OK)
                    {
                        return;
                    }

                    KeyChainManager.isNamed = d.FileName;
                    MemoryStream memoryStream = new MemoryStream();
                    Text = d.FileName;
                    KeyChainManager.KeyChain.IsModified = false;
                    DataContractSerializer dcs = new DataContractSerializer(typeof(KeyChain));
                    dcs.WriteObject(memoryStream, KeyChainManager.KeyChain);
                    Byte[] ToWrite = CryptoHelper.Encrypt(memoryStream.ToArray(), newpass);
                    File.WriteAllBytes(d.FileName, ToWrite);
                    memoryStream.Close();

                    //Dropbox removed for demo
                    //DropNetClient Dropbox;
                    //enter Tokens and keys in next line to use dropbox.  Removed for demo
                    //Dropbox = new DropNetClient();
                    //Dropbox.UseSandbox = true;
                    //var uploaded = Dropbox.UploadFile("/", Path.GetFileName(d.FileName), ToWrite);
                }
            }
        }
Пример #4
0
        public void Open()
        {
            OpenFileDialog d = new OpenFileDialog();

            if (d.FileName != null)
            {
                string exe = Assembly.GetExecutingAssembly().Location;
                d.InitialDirectory = Path.GetDirectoryName(exe);
                d.RestoreDirectory = true;
                d.Filter           = "KeyChain Files|*.kcf";
                if (d.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
                else
                {
                    PasswordForm p = new PasswordForm();
                    p.local    = File.ReadAllBytes(d.FileName);
                    p.savethis = 2;
                    p.ShowDialog();
                    if (p.DialogResult != DialogResult.OK)
                    {
                        return;
                    }
                    string       pass = p.Password;
                    MDIChildForm form = new MDIChildForm();
                    form.Fsize     = this.FontSize;
                    form.Ftype     = this.FontSelected;
                    form.MdiParent = this;
                    form.Show();


                    DataContractSerializer dcs = new DataContractSerializer(typeof(KeyChain));
                    byte[] ToRead         = File.ReadAllBytes(d.FileName);
                    byte[] decryptedArray = CryptoHelper.Decrypt(ToRead, pass);
                    if (decryptedArray != null)
                    {
                        MemoryStream memoryreadStream = new MemoryStream(decryptedArray);
                        KeyChainManager.KeyChain = (KeyChain)dcs.ReadObject(memoryreadStream);
                        memoryreadStream.Close();
                        form.LoadFile();
                        //foreach (Group g in KeyChainManager.KeyChain.Groups)
                        //{
                        //form.groupTreeControl1.AddTreeNodefromFileLoad(g);
                        //statusStripGroupTotal(g);
                        //}

                        statusStripControl1.StatusBarComboboxClear();
                        KeyChainManager.KeyChain.IsModified = false;
                        Text = d.FileName;
                    }
                    else
                    {
                        form.Close();
                        MessageBox.Show("Wrong Password Entered.  Please try to load File again, select a different file, create a new file, or exit.");
                    }
                }
            }



            statusStripControl1.StatusBarComboboxClear();
            KeyChainManager.KeyChain.IsModified = false;
            Text = d.FileName;
        }