Class Hash
java.lang.Object
com.pnfsoftware.jeb.util.encoding.Hash
Hash calculation routines. To calculate multiple hashes in a more efficient way, use
HashCalculator instead.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcalculateCRC32(byte[] data) Compute a CRC-32 checksum for a byte array.static byte[]calculateMD5(byte[] data) Compute an MD5 digest for a byte array.static byte[]calculateSHA1(byte[] data) Compute a SHA-1 digest for a byte array.static byte[]calculateSHA256(byte[] data) Compute a SHA-256 digest for a byte array.static voidUpdate a checksum with all bytes of a file.static voidchecksumBlockFileUpdate(Checksum h, File f, long offset, long size) Update a checksum with a byte range of a file.static voidchecksumBlockFileUpdate(Checksum h, RandomAccessFile raf, long size) Update a checksum with bytes read from the current position of a random-access file.
-
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
Update a checksum with all bytes of a file.- Parameters:
h- checksum to updatef- 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 updatef- input fileoffset- start offset in the filesize- 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 updateraf- input file, positioned at the start of the rangesize- number of bytes to read- Throws:
IOException- if the requested byte range cannot be read
-