public static byte[] ReadNonce(string filePath, byte[] salt, int parametersLength)
        {
            NullChecks.ByteArray(salt);
            int headerLength = 0;
            int offset       = salt.Length + parametersLength;

            if (Globals.EncryptionAlgorithm == (int)Cipher.XChaCha20 || Globals.EncryptionAlgorithm == (int)Cipher.XSalsa20)
            {
                headerLength = Constants.XChaChaNonceLength;
            }
            else if (Globals.EncryptionAlgorithm == (int)Cipher.AesCBC)
            {
                headerLength = Constants.AesNonceLength;
            }
            return(ReadHeader(filePath, headerLength, offset));
        }
Exemple #2
0
 public static bool AppendHash(string filePath, byte[] fileHash)
 {
     try
     {
         NullChecks.ByteArray(fileHash);
         using (var fileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.Read))
         {
             fileStream.Write(fileHash, 0, fileHash.Length);
         }
         return(true);
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(filePath, ex.GetType().Name, "Unable to append the MAC to the file. This data is required for decryption of the file.");
         return(false);
     }
 }