Ejemplo n.º 1
0
 private void uhhSomethingToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (currentET != null)
     {
         using (var f = new PasswordForm()) {
             if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 var ne = currentET.Clone(f.Key.DecodeToString());
                 currentET.Dispose();
                 currentET = ne;
             }
         }
     }
 }
Ejemplo n.º 2
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var sfd = new SaveFileDialog())
            {
                sfd.Title  = "Save File";
                sfd.Filter = "Encrypted Text Files|*.et|All Files|*.*";
                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    using (var f = new PasswordForm())
                    {
                        if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            reset();
                            currentFile = sfd.FileName;
                            currentET   = new et.EncryptedText(f.Key.DecodeToString());
                            save();

                            /*if(!settings.disableReadPadding)
                             *   currentET.PadSettings = padding;
                             *
                             * byte[] by = currentET.Encrypt(richTextBox1.Text);
                             *
                             * et.EncryptedTextContainer c = new et.EncryptedTextContainer() { Data = by, Salt = currentET.Salt };
                             * try
                             * {
                             *  using (var fs = new FileStream(currentFile, FileMode.Create))
                             *  {
                             *      c.Save(fs);
                             *      prevHash = richTextBox1.Text.EncodeToByteArray().SHA1Hash();
                             *  }
                             * }
                             * catch (Exception ex)
                             * {
                             *  MessageBox.Show("Error saving: " + ex.Message);
                             * }*/
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private void load(string fn)
 {
     reset();
     try
     {
         using (var s = new FileStream(fn, FileMode.Open, FileAccess.Read))
         {
             et.EncryptedTextContainer t = new et.EncryptedTextContainer();
             t.Load(s);
             using (var f = new PasswordForm())
             {
                 if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                 {
                     currentET = new et.EncryptedText(f.Key.DecodeToString(), t.Salt);
                     if (settings.forceCurrentPadding)
                     {
                         currentET.PadSettings = padding;
                     }
                     else if (!settings.disableReadPadding)
                     {
                         padding = currentET.PadSettings;//does this even do anything?
                     }
                     richTextBox1.Text = currentET.Decrypt(t.Data);
                     currentFile       = fn;
                     prevHash          = richTextBox1.Text.EncodeToByteArray().SHA1Hash();
                     //TODO: Load efs
                 }
             }
         }
     }
     catch (Exception ex)
     {
         reset();
         MessageBox.Show("Could not open file: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }