Ejemplo n.º 1
0
 void save()
 {
     //todo: save efs
     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.º 2
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);
     }
 }