Пример #1
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            try
            {
                AES256 aes = new AES256(txtPassphrase.Text);
                if (pnl_folder.Visible)
                {
                    List <string> pathes = DirSearch(txtSelectFolder.Text, false);
                    foreach (string path in pathes)
                    {
                        aes.EncryptFile(path, path + "." + ENCRYPTED_FILE_EXTANTION);
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                    }
                }
                else
                {
                    string path = txtOpenFile.Text;
                    aes.EncryptFile(path, path + "." + ENCRYPTED_FILE_EXTANTION);
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }

                clearForm();
                setResultLabel(true);
            }
            catch (Exception exp)
            {
                setResultLabel(false, exp.Message);
            }
        }
Пример #2
0
 private void btnDecrypt_Click(object sender, EventArgs e)
 {
     try
     {
         AES256 aes = new AES256(txtPassphrase.Text);
         if (pnl_folder.Visible)
         {
             List <string> pathes = DirSearch(txtSelectFolder.Text, true);
             foreach (string path in pathes)
             {
                 string newPath = path.Substring(0, path.Length - ENCRYPTED_FILE_EXTANTION.Length - 1);
                 aes.DecryptFile(path, newPath);
                 if (File.Exists(path))
                 {
                     File.Delete(path);
                 }
             }
         }
         else
         {
             string path    = txtOpenFile.Text;
             string newPath = path.Substring(0, path.Length - ENCRYPTED_FILE_EXTANTION.Length - 1);
             aes.DecryptFile(txtOpenFile.Text, newPath);
             if (File.Exists(path))
             {
                 File.Delete(path);
             }
         }
         clearForm();
         setResultLabel(true);
     }
     catch (Exception exp)
     {
         if (exp.Message == "Padding is invalid and cannot be removed.")
         {
             setResultLabel(false, "Wrong Password");
         }
         else if (exp.Message == "Length of the data to decrypt is invalid.")
         {
             setResultLabel(false, "File is not encrypted");
         }
         else
         {
             setResultLabel(false, exp.Message);
         }
     }
 }