Class BackupHelper

java.lang.Object
org.cryptomator.cryptofs.common.BackupHelper

public final class BackupHelper extends Object
Utility class for generating a suffix for the backup file to make it unique to its original file.
  • Method Details

    • generateFileIdSuffix

      public static String generateFileIdSuffix(byte[] fileBytes)
      Computes the SHA-256 digest of the given byte array and returns a file suffix containing the first 4 bytes in hex string format.
      Parameters:
      fileBytes - the input byte for which the digest is computed
      Returns:
      "." + first 4 bytes of SHA-256 digest in hex string format
    • attemptBackup

      public static Path attemptBackup(Path path) throws IOException
      Do a best-effort attempt to back up the file at the given path. Fails silently if a _valid_ backup already exists and fails with a log entry, if any IO error occurs while creating or reading the backup file.
      Parameters:
      path - The file to back up
      Throws:
      IOException - If the path cannot be read.