Class Hash

java.lang.Object
com.pnfsoftware.jeb.util.encoding.Hash

public class Hash extends Object
Hash calculation routines. To calculate multiple hashes in a more efficient way, use HashCalculator instead.
  • Constructor Details

    • Hash

      public Hash()
  • Method Details

    • calculateCRC32

      public static int calculateCRC32(byte[] data)
      Compute a CRC-32 checksum for a byte array.
      Parameters:
      data - input bytes
      Returns:
      CRC-32 value, truncated to an int
    • calculateMD5

      public static byte[] calculateMD5(byte[] data)
      Compute an MD5 digest for a byte array.
      Parameters:
      data - input bytes
      Returns:
      16-byte MD5 digest
    • calculateSHA1

      public static byte[] calculateSHA1(byte[] data)
      Compute a SHA-1 digest for a byte array.
      Parameters:
      data - input bytes
      Returns:
      20-byte SHA-1 digest
    • calculateSHA256

      public static byte[] calculateSHA256(byte[] data)
      Compute a SHA-256 digest for a byte array.
      Parameters:
      data - input bytes
      Returns:
      32-byte SHA-256 digest
    • checksumBlockFileUpdate

      public static void checksumBlockFileUpdate(Checksum h, File f) throws IOException
      Update a checksum with all bytes of a file.
      Parameters:
      h - checksum to update
      f - input file
      Throws:
      IOException - if the file cannot be read
    • checksumBlockFileUpdate

      public static void checksumBlockFileUpdate(Checksum h, File f, long offset, long size) throws IOException
      Update a checksum with a byte range of a file.
      Parameters:
      h - checksum to update
      f - input file
      offset - start offset in the file
      size - number of bytes to read
      Throws:
      IOException - if the file range cannot be read
    • checksumBlockFileUpdate

      public static void checksumBlockFileUpdate(Checksum h, RandomAccessFile raf, long size) throws IOException
      Update a checksum with bytes read from the current position of a random-access file.
      Parameters:
      h - checksum to update
      raf - input file, positioned at the start of the range
      size - number of bytes to read
      Throws:
      IOException - if the requested byte range cannot be read