Esempio n. 1
0
        //private string GetKey()
        //{
        //    //returns the default encryption key which is itself encrypted and stored in the text file "setup.dll"
        //    string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
        //    string[] key = File.ReadAllLines(appDirectory + "setup.dll");
        //    return StringCipher.Decrypt(key[0]);
        //}

        private void btnFileEncrypt_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;                                                          // should be >= 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 + ".dlr";
                        if (File.Exists(destinationFilename))
                        {
                            File.Delete(destinationFilename);
                        }

                        StringCipher.EncryptFile(source, destinationFilename, password, salt, iterations);
                        if (deleteSource)
                        {
                            File.Delete(source);
                        }
                    }
                }
                tbFilePath.Text  = "";
                cbDelete.Checked = false;
            }catch (Exception ex)
            {
                MessageBox.Show("Something went wrong." + Environment.NewLine + "Check the log for the error message");
                lm.Write(ex.Message);
            }
        }