private void ButtonEncrypt_Click(object sender, RoutedEventArgs e)
 {
     iv = null;
     if (string.IsNullOrWhiteSpace(textBoxPW.Text))
     {
         MessageBox.Show(
             "Passwort darf nicht leer sein!",
             "Fehler",
             MessageBoxButton.OK,
             MessageBoxImage.Error);
         assistant.WriteLog("Fehler: Passwort leer!");
     }
     else if (string.IsNullOrWhiteSpace(textBoxIN.Text))
     {
         MessageBox.Show(
             "Eingabefeld darf nicht leer sein!",
             "Fehler",
             MessageBoxButton.OK,
             MessageBoxImage.Error);
         assistant.WriteLog("Fehler: Eingabe leer!");
     }
     else
     {
         try
         {
             if (iv == null)
             {
                 iv = assistant.RandomGen(16);
                 assistant.WriteLog("IV erstellt!");
             }
             assistant.CreateSalt();
             assistant.SetIV(iv);
             assistant.SetPW(textBoxPW.Text);
             aes.SetParams(assistant.GetPW(), assistant.GetIV());
             textBoxOUT.Text = aes.Encrypt(textBoxIN.Text);
             if (CheckBoxAddIV.IsChecked == true)
             {
                 textBoxOUT.Text += " :::/ " + assistant.GetIV() + " ::::: " + assistant.GetSalt();
             }
             assistant.WriteLog("Text verschlüsselt!");
         }
         catch (Exception err)
         {
             MessageBox.Show(
                 "Kann nicht Verschlüsseln!",
                 "Fehler",
                 MessageBoxButton.OK,
                 MessageBoxImage.Error);
             assistant.WriteLog("Fehler: Verschlüsseln fehlgeschlagen! " + err.Message);
         }
     }
 }
Example #2
0
        public MainWindow()
        {
            InitializeComponent();
            if (!Directory.Exists(dataDir))
            {
                Directory.CreateDirectory(dataDir);
                assistant.CreateSalt();
                assistant.SetIV(assistant.RandomGen(16));
                StreamWriter sw = File.AppendText(cryptoData);
                sw.Write("IV:" + assistant.GetIV() + Environment.NewLine);
                sw.Write("Salt:" + assistant.GetSalt());
                sw.Close();
            }
            else
            {
            }
            string content = File.ReadAllText(cryptoData);

            assistant.SetIV(content.Substring(3, 16));
            assistant.SetSalt(content.Substring(content.LastIndexOf("Salt:") + 5));
            assistant.SetPW(pass);
            myAes.SetParams(assistant.GetPW(), assistant.GetIV());
        }