Beispiel #1
0
        private void btnFileDecrypt_Click(object sender, EventArgs e)
        {
            byte[] salt                = new byte[] { 0x49, 0x54, 0x54, 0x56, 0x49, 0x51, 0x55, 0x49 }; // Must be at least eight bytes
            int    iterations          = 1052;                                                          // >= 1000.
            string password            = tbFileKey.Text.Length > 0 ? tbFileKey.Text.Trim() : "";        // GetKey();
            string destinationFilename = "";
            string sourceFilename      = tbFilePath.Text;

            string[] sourceFiles = sourceFilename.Split(Environment.NewLine.ToCharArray());
            try
            {
                foreach (string source in sourceFiles)
                {
                    if (source.Length > 0)
                    {
                        destinationFilename = source.Substring(0, source.Length - 4);
                        if (File.Exists(destinationFilename)) //if the original unencrypted file is present, delete it.
                        {
                            File.Delete(destinationFilename);
                        }
                        StringCipher.DecryptFile(source, destinationFilename, password, salt, iterations);
                        File.Delete(source);
                    }
                }
                tbFilePath.Text = "";
            }catch (Exception ex)
            {
                MessageBox.Show("Did you mean to click \"Encrypt\"?" + Environment.NewLine + "if not then check the log for the error message.");
                lm.Write(ex.Message);
            }
        }