Exemplo n.º 1
0
 internal static void HandleException(Exception e)
 {
     if (!_verbose)
     {
         Logging.Log(FileAES_Utilities.FAES_ExceptionHandling(e), Severity.ERROR);
     }
     else
     {
         Logging.Log(String.Format("Verbose Mode Enabled: Showing Full Exception...\n{0}\n\nConsole held open. Press any key to exit.", e.ToString()), Severity.ERROR);
         Console.ReadKey();
     }
 }
Exemplo n.º 2
0
 internal static void HandleException(Exception e)
 {
     if (!_verbose)
     {
         Console.WriteLine(FileAES_Utilities.FAES_ExceptionHandling(e));
     }
     else
     {
         Console.WriteLine("[ERROR] Verbose Mode Enabled: Showing Full Exception...\n");
         Console.WriteLine(e.ToString());
         Console.WriteLine("\n\nConsole held open. Press any key to exit.");
         Console.ReadKey();
     }
 }
Exemplo n.º 3
0
        private void Decrypt()
        {
            try
            {
                SetNote("Decrypting... Please wait.", 0);

                _inProgress        = true;
                _decryptSuccessful = false;

                while (!backgroundDecrypt.CancellationPending)
                {
                    FAES.FileAES_Decrypt decrypt = new FAES.FileAES_Decrypt(_fileToPeek, passwordInput.Text, false, true);

                    _pathOverride = Path.Combine(Path.GetDirectoryName(_fileToPeek.getPath()), "faesPeekFilePath_" + new Random().Next(), "peekFile" + FileAES_Utilities.ExtentionUFAES);
                    string dirName = Path.GetDirectoryName(_pathOverride);
                    _finalPath = Path.Combine(dirName, _fileToPeek.GetOriginalFileName());

                    DirectoryInfo di = Directory.CreateDirectory(dirName);
                    di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;

                    Thread dThread = new Thread(() =>
                    {
                        try
                        {
                            _decryptSuccessful = decrypt.decryptFile(_pathOverride);
                        }
                        catch (Exception e)
                        {
                            SetNote(FileAES_Utilities.FAES_ExceptionHandling(e), 3);
                        }
                    });
                    dThread.Start();

                    while (dThread.ThreadState == ThreadState.Running)
                    {
                        _progress = decrypt.GetDecryptionPercentComplete();
                    }

                    backgroundDecrypt.CancelAsync();
                }
            }
            catch (Exception e)
            {
                SetNote(FileAES_Utilities.FAES_ExceptionHandling(e), 3);
            }
        }
Exemplo n.º 4
0
        private void Encrypt()
        {
            try
            {
                SetNote("Encrypting... Please wait.", 0);

                _inProgress        = true;
                _encryptSuccessful = false;

                while (!backgroundEncrypt.CancellationPending)
                {
                    FileAES_Utilities.LocalEncrypt = Program.UseLocalEncrypt();
                    FAES.FileAES_Encrypt encrypt = new FAES.FileAES_Encrypt(_fileToEncrypt, passwordInput.Text, hintInput.Text);

                    encrypt.SetCompressionMode(_compressionMode);
                    encrypt.SetDeleteAfterEncrypt(_deleteOriginal);
                    encrypt.SetOverwriteDuplicate(_overwriteDuplicate);

                    Thread eThread = new Thread(() =>
                    {
                        try
                        {
                            _encryptSuccessful = encrypt.encryptFile();
                        }
                        catch (Exception e)
                        {
                            SetNote(FileAES_Utilities.FAES_ExceptionHandling(e), 3);
                        }
                    });
                    eThread.Start();

                    while (eThread.ThreadState == ThreadState.Running)
                    {
                        _progress = encrypt.GetEncryptionPercentComplete();
                    }

                    backgroundEncrypt.CancelAsync();
                }
            }
            catch (Exception e)
            {
                SetNote(FileAES_Utilities.FAES_ExceptionHandling(e), 3);
            }
        }
Exemplo n.º 5
0
        private void Decrypt()
        {
            try
            {
                SetNote("Decrypting... Please wait.", 0);

                _inProgress        = true;
                _decryptSuccessful = false;

                while (!backgroundDecrypt.CancellationPending)
                {
                    FAES.FileAES_Decrypt decrypt = new FAES.FileAES_Decrypt(_fileToDecrypt, passwordInput.Text, _deleteOriginal, _overwriteDuplicate);

                    Thread dThread = new Thread(() =>
                    {
                        try
                        {
                            _decryptSuccessful = decrypt.decryptFile();
                        }
                        catch (Exception e)
                        {
                            SetNote(FileAES_Utilities.FAES_ExceptionHandling(e), 3);
                        }
                    });
                    dThread.Start();

                    while (dThread.ThreadState == ThreadState.Running)
                    {
                        _progress = decrypt.GetDecryptionPercentComplete();
                    }

                    backgroundDecrypt.CancelAsync();
                }
            }
            catch (Exception e)
            {
                SetNote(FileAES_Utilities.FAES_ExceptionHandling(e), 3);
            }
        }
Exemplo n.º 6
0
        private void Decrypt()
        {
            string password    = passTextbox.Text;
            bool   delAfterEnc = deleteOriginal.Checked;
            bool   ovDup       = overwriteDuplicate.Checked;

            Logging.Log("FAES_GUI(Decrypt): Started!'", Severity.DEBUG);

            SetNote("Decrypting... Please wait.", 0);

            _inProgress        = true;
            _decryptSuccessful = false;

            _mainDecryptThread = new Thread(() =>
            {
                try
                {
                    FileAES_Utilities.SetCryptoStreamBuffer(Program.programManager.GetCryptoStreamBufferSize());
                    FileAES_Decrypt decrypt = new FileAES_Decrypt(_fileToDecrypt, password, delAfterEnc, ovDup);
                    decrypt.DebugMode       = FileAES_Utilities.GetVerboseLogging();

                    _faesThread = new Thread(() =>
                    {
                        try
                        {
                            _decryptSuccessful = decrypt.DecryptFile();
                        }
                        catch (Exception e)
                        {
                            SetNote(FileAES_Utilities.FAES_ExceptionHandling(e, Program.IsVerbose()).Replace("ERROR:", ""), 3);
                        }
                    });
                    _faesThread.Start();

                    while (_faesThread.ThreadState == ThreadState.Running)
                    {
                        _progress = decrypt.GetPercentComplete();
                    }

                    {
                        _inProgress = false;

                        Invoke(new MethodInvoker(() => Locked(false)));

                        if (_decryptSuccessful)
                        {
                            Logging.Log("FAES_GUI(Decrypt): Finished successfully!'", Severity.DEBUG);
                            SetNote("Decryption Complete", 0);
                            progressBar.CustomText = "Done";
                            progressBar.VisualMode = CustomControls.ProgressBarDisplayMode.TextAndPercentage;
                            if (_closeAfterOp)
                            {
                                Application.Exit();
                            }
                            else
                            {
                                ResetFile();
                            }
                        }
                        else
                        {
                            decryptionTimer.Stop();
                            progressBar.ProgressColor = Color.Red;
                            progressBar.Value         = progressBar.Maximum;

                            Logging.Log("FAES_GUI(Decrypt): Finished unsuccessfully!'", Severity.DEBUG);
                            if (!statusInformation.Text.ToLower().Contains("error"))
                            {
                                SetNote("Password Incorrect!", 3);
                                progressBar.CustomText = "Password Incorrect!";
                                progressBar.VisualMode = CustomControls.ProgressBarDisplayMode.TextAndPercentage;
                                Invoke(new Action(() => passTextbox.Focus()));
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    SetNote(FileAES_Utilities.FAES_ExceptionHandling(e, Program.IsVerbose()).Replace("ERROR:", ""), 3);
                }
            });
            _mainDecryptThread.Start();
        }
Exemplo n.º 7
0
        private void Decrypt()
        {
            Logging.Log("FAES_GUI(Decrypt): Started!'", Severity.DEBUG);
            string pathOverride = Path.Combine(Path.GetDirectoryName(_fileToPeek.GetPath()) ?? string.Empty, "faesPeekFilePath_" + new Random().Next(), "peekFile" + FileAES_Utilities.ExtentionUFAES);
            string dirName      = Path.GetDirectoryName(pathOverride);
            string password     = passTextbox.Text;
            string finalPath    = Path.Combine(dirName ?? string.Empty, _fileToPeek.GetOriginalFileName());

            DirectoryInfo di = Directory.CreateDirectory(dirName ?? string.Empty);

            di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;

            SetNote("Decrypting... Please wait.", 0);

            _inProgress        = true;
            _decryptSuccessful = false;

            _mainDecryptThread = new Thread(() =>
            {
                try
                {
                    FileAES_Utilities.SetCryptoStreamBuffer(Program.programManager.GetCryptoStreamBufferSize());
                    FileAES_Decrypt decrypt = new FileAES_Decrypt(_fileToPeek, password, false);
                    decrypt.DebugMode       = FileAES_Utilities.GetVerboseLogging();

                    _faesThread = new Thread(() =>
                    {
                        try
                        {
                            _decryptSuccessful = decrypt.DecryptFile(pathOverride);
                        }
                        catch (Exception e)
                        {
                            SetNote(FileAES_Utilities.FAES_ExceptionHandling(e, Program.IsVerbose()).Replace("ERROR:", ""), 3);
                        }
                    });
                    _faesThread.Start();

                    while (_faesThread.ThreadState == ThreadState.Running)
                    {
                        _progress = decrypt.GetPercentComplete();
                    }

                    {
                        _inProgress = false;
                        Invoke(new MethodInvoker(() => Locked(false)));

                        if (_decryptSuccessful)
                        {
                            Logging.Log("FAES_GUI(Decrypt): Finished successfully!'", Severity.DEBUG);
                            SetNote("Decryption Complete", 0);
                            progressBar.CustomText = "Done";
                            progressBar.VisualMode = CustomControls.ProgressBarDisplayMode.TextAndPercentage;

                            Invoke(new MethodInvoker(() =>
                            {
                                fileContentsTextbox.Text = File.ReadAllText(finalPath);
                            }));
                            Delete(pathOverride);
                        }
                        else
                        {
                            decryptionTimer.Stop();
                            progressBar.ProgressColor = Color.Red;
                            progressBar.Value         = progressBar.Maximum;

                            Logging.Log("FAES_GUI(Decrypt): Finished unsuccessfully!'", Severity.DEBUG);
                            if (!statusInformation.Text.ToLower().Contains("error"))
                            {
                                SetNote("Password Incorrect!", 3);
                                progressBar.CustomText = "Password Incorrect!";
                                progressBar.VisualMode = CustomControls.ProgressBarDisplayMode.TextAndPercentage;
                                Invoke(new Action(() => passTextbox.Focus()));
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    SetNote(FileAES_Utilities.FAES_ExceptionHandling(e, Program.IsVerbose()).Replace("ERROR:", ""), 3);
                }
                finally
                {
                    Delete(pathOverride);
                }
            });
            _mainDecryptThread.Start();
        }
Exemplo n.º 8
0
        private void Encrypt()
        {
            string password      = passTextbox.Text;
            string passHint      = passHintTextbox.Text;
            int    compressIndex = compressMode.SelectedIndex;
            bool   delAfterEnc   = deleteOriginal.Checked;
            bool   ovDup         = overwriteDuplicate.Checked;

            Logging.Log("FAES_GUI(Encrypt): Started!'", Severity.DEBUG);

            SetNote("Encrypting... Please wait.", 0);

            _inProgress        = true;
            _encryptSuccessful = false;

            _mainEncryptThread = new Thread(() =>
            {
                try
                {
                    FileAES_Utilities.SetCryptoStreamBuffer(Program.programManager.GetCryptoStreamBufferSize());
                    FileAES_Utilities.TempEncrypt = Program.programManager.GetUseOSTemp();
                    FileAES_Encrypt encrypt       = new FileAES_Encrypt(_fileToEncrypt, password, passHint, FAES.Packaging.CompressionUtils.GetAllOptimiseModes()[compressIndex]);
                    encrypt.SetDeleteAfterEncrypt(delAfterEnc);
                    encrypt.SetOverwriteDuplicate(ovDup);
                    encrypt.DebugMode = FileAES_Utilities.GetVerboseLogging();

                    _faesThread = new Thread(() =>
                    {
                        try
                        {
                            _encryptSuccessful = encrypt.EncryptFile();
                        }
                        catch (Exception e)
                        {
                            SetNote(FileAES_Utilities.FAES_ExceptionHandling(e, Program.IsVerbose()).Replace("ERROR:", ""), 3);
                        }
                    });
                    _faesThread.Start();

                    while (_faesThread.ThreadState == ThreadState.Running)
                    {
                        _progress = encrypt.GetPercentComplete();
                    }

                    {
                        _inProgress = false;

                        Invoke(new MethodInvoker(() => Locked(false)));

                        if (_encryptSuccessful)
                        {
                            Logging.Log("FAES_GUI(Encrypt): Finished successfully!'", Severity.DEBUG);
                            SetNote("Encryption Complete", 0);
                            progressBar.CustomText = "Done";
                            progressBar.VisualMode = CustomControls.ProgressBarDisplayMode.TextAndPercentage;
                            if (_closeAfterOp)
                            {
                                Application.Exit();
                            }
                            else
                            {
                                ResetFile();
                            }
                        }
                        else
                        {
                            Logging.Log("FAES_GUI(Encrypt): Finished unsuccessfully!'", Severity.DEBUG);
                            if (!statusInformation.Text.ToLower().Contains("error"))
                            {
                                SetNote("Encryption Failed. Try again later.", 1);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    SetNote(FileAES_Utilities.FAES_ExceptionHandling(e, Program.IsVerbose()).Replace("ERROR:", ""), 3);
                }
            });
            _mainEncryptThread.Start();
        }