Пример #1
0
 public static void UsingPassword(string directoryPath, byte[] passwordBytes)
 {
     try
     {
         string[] filePaths    = GetFiles(directoryPath);
         string   saltFilePath = Path.Combine(directoryPath, Constants.SaltFile);
         if (!File.Exists(saltFilePath))
         {
             throw new FileNotFoundException("No salt file found. Unable to decrypt the directory. Please decrypt these files individually.");
         }
         byte[] salt = File.ReadAllBytes(saltFilePath);
         if (salt.Length != Constants.SaltLength)
         {
             throw new ArgumentException("Invalid salt length.");
         }
         byte[] keyEncryptionKey = Argon2.DeriveKey(passwordBytes, salt);
         DecryptEachFileWithPassword(filePaths, keyEncryptionKey);
         Finalize(directoryPath, saltFilePath);
     }
     catch (Exception ex) when(ExceptionFilters.FileAccess(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.Error);
         if (ex is ArgumentException || ex is FileNotFoundException)
         {
             DisplayMessage.FilePathError(directoryPath, ex.Message);
             return;
         }
         DisplayMessage.FilePathException(directoryPath, ex.GetType().Name, "Unable to decrypt the directory.");
     }
 }
Пример #2
0
        public static bool FileEncryption(string inputFilePath)
        {
            string errorMessage = GetFileEncryptionError(inputFilePath);

            if (string.IsNullOrEmpty(errorMessage))
            {
                return(true);
            }
            DisplayMessage.FilePathError(inputFilePath, errorMessage);
            return(false);
        }
Пример #3
0
        public static bool FileDecryption(string inputFilePath)
        {
            if (inputFilePath.Contains(Constants.SaltFile))
            {
                return(false);
            }
            string errorMessage = GetFileDecryptionError(inputFilePath);

            if (string.IsNullOrEmpty(errorMessage))
            {
                return(true);
            }
            DisplayMessage.FilePathError(inputFilePath, errorMessage);
            return(false);
        }