Ejemplo n.º 1
0
        public static bool IsFileValidForPeek(FAES_File file)
        {
            if (file.IsFileDecryptable())
            {
                return(_supportedPeekFiles.Contains(Path.GetExtension(file.GetOriginalFileName()).ToUpper()));
            }

            return(false);
        }
Ejemplo n.º 2
0
        public void FAESv3_MetaData()
        {
            string filePath = "ExampleFiles/EncryptedFiles/FAESv3.faes";

            string expectedOriginalName = "Example.txt";
            string expectedHint         = "Hint";
            string expectedVer          = "v1.2.0-RC_1";

            string actualOriginalName = string.Empty;
            string actualHint         = string.Empty;
            string actualVer          = string.Empty;

            try
            {
                FileAES_Utilities.SetVerboseLogging(true);

                FAES_File faesFile = new FAES_File(filePath);

                actualOriginalName = faesFile.GetOriginalFileName();
                if (expectedOriginalName != actualOriginalName)
                {
                    Assert.Fail("Incorrect original name!");
                }

                actualHint = faesFile.GetPasswordHint();
                if (expectedHint != actualHint)
                {
                    Assert.Fail("Incorrect password hint!");
                }

                actualVer = faesFile.GetEncryptionVersion();
                if (expectedVer != actualVer)
                {
                    Assert.Fail("Incorrect encryption version!");
                }

                // TODO: Add more metadata checks
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }
            finally
            {
                Console.WriteLine("\r\n=== Test Values ===\r\n");
                Console.WriteLine("Expected Name: '{0}' | Actual Name: '{1}'", expectedOriginalName, actualOriginalName);
                Console.WriteLine("Expected Hint: '{0}' | Actual Hint: '{1}'", expectedHint, actualHint);
                Console.WriteLine("Expected Ver: '{0}' | Actual Ver: '{1}'", expectedVer, actualVer);
            }
        }
Ejemplo 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);
            }
        }
Ejemplo n.º 4
0
Archivo: LZMA.cs Proyecto: fileaes/FAES
        /// <summary>
        /// Decompress an encrypted FAES File.
        /// </summary>
        /// <param name="encryptedFile">Encrypted FAES File</param>
        /// <param name="overridePath">Override the read path</param>
        /// <returns>Path of the encrypted, Decompressed file</returns>
        public string DecompressFAESFile(FAES_File encryptedFile, string overridePath = "")
        {
            string path;

            if (!String.IsNullOrWhiteSpace(overridePath))
            {
                path = overridePath;
            }
            else
            {
                path = Path.ChangeExtension(encryptedFile.GetPath(), FileAES_Utilities.ExtentionUFAES);
            }

            using (Stream stream = File.OpenRead(path))
            {
                var reader = ReaderFactory.Open(stream);
                while (reader.MoveToNextEntry())
                {
                    reader.WriteEntryToDirectory(Directory.GetParent(Path.ChangeExtension(path, Path.GetExtension(encryptedFile.GetOriginalFileName())))?.FullName, new ExtractionOptions()
                    {
                        ExtractFullPath = true, Overwrite = true
                    });
                }
            }
            return(path);
        }
Ejemplo n.º 5
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();
        }