Example #1
0
        private static void CompleteEncryption(string filePath, string encryptedFilePath, byte[] macKey)
        {
            // Calculate and append MAC
            bool fileSigned = FileAuthentication.SignFile(encryptedFilePath, macKey);

            Utilities.ZeroArray(macKey);
            if (fileSigned == true && Globals.OverwriteFiles == true)
            {
                FileHandling.OverwriteFile(filePath, encryptedFilePath);
            }
            FileHandling.MakeFileReadOnly(encryptedFilePath);
            GetEncryptionResult(filePath, fileSigned);
        }
Example #2
0
        private static void CheckForTampering(string filePath, int parametersLength, byte[] encryptionKey, byte[] macKey, BackgroundWorker bgwDecryption)
        {
            bool fileTampered = FileAuthentication.AuthenticateFile(filePath, macKey, out byte[] macBackup);

            Utilities.ZeroArray(macKey);
            if (fileTampered == false)
            {
                DecryptFile(filePath, parametersLength, macBackup, encryptionKey, bgwDecryption);
            }
            else
            {
                Globals.ResultsText += $"{Path.GetFileName(filePath)}: Incorrect password/keyfile or this file has been tampered with.{Environment.NewLine}";
                Utilities.ZeroArray(encryptionKey);
            }
        }
Example #3
0
        private static void RestoreMAC(string filePath, byte[] macBackup)
        {
            bool restored = FileAuthentication.AppendHash(filePath, macBackup);

            if (restored == false)
            {
                try
                {
                    File.WriteAllBytes($"{filePath}.backup", macBackup);
                }
                catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
                {
                    Logging.LogException(ex.ToString(), Logging.Severity.High);
                    DisplayMessage.ErrorResultsText(filePath, ex.GetType().Name, "Failed to backup the MAC. This data is required for decryption.");
                }
            }
            Utilities.ZeroArray(macBackup);
        }