public final class Checksum
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
getChecksum(java.lang.String algorithm,
byte[] bytes)
Calculates the MD5 checksum of a specified bytes.
|
static java.lang.String |
getChecksum(java.lang.String algorithm,
java.io.File file)
Creates the cryptographic checksum of a given file using the specified
algorithm.
|
static java.lang.String |
getHex(byte[] raw)
Converts a byte array into a hex string.
|
static java.lang.String |
getMD5Checksum(java.io.File file)
Calculates the MD5 checksum of a specified file.
|
static java.lang.String |
getMD5Checksum(java.lang.String text)
Calculates the MD5 checksum of the specified text.
|
static java.lang.String |
getSHA1Checksum(java.io.File file)
Calculates the SHA1 checksum of a specified file.
|
static java.lang.String |
getSHA1Checksum(java.lang.String text)
Calculates the SHA1 checksum of the specified text.
|
static java.lang.String |
getSHA256Checksum(java.io.File file)
Calculates the SH256 checksum of a specified file.
|
static java.lang.String |
getSHA256Checksum(java.lang.String text)
Calculates the SHA256 checksum of the specified text.
|
public static java.lang.String getChecksum(java.lang.String algorithm,
java.io.File file)
throws java.security.NoSuchAlgorithmException,
java.io.IOException
Creates the cryptographic checksum of a given file using the specified algorithm.
algorithm - the algorithm to use to calculate the checksumfile - the file to calculate the checksum forjava.io.IOException - when the file does not existjava.security.NoSuchAlgorithmException - when an algorithm is
specified that does not existpublic static java.lang.String getMD5Checksum(java.io.File file)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
file - the file to generate the MD5 checksumjava.io.IOException - when the file passed in does not existjava.security.NoSuchAlgorithmException - when the MD5 algorithm is
not availablepublic static java.lang.String getSHA1Checksum(java.io.File file)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
file - the file to generate the MD5 checksumjava.io.IOException - when the file passed in does not existjava.security.NoSuchAlgorithmException - when the SHA1 algorithm is
not availablepublic static java.lang.String getSHA256Checksum(java.io.File file)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
file - the file to generate the MD5 checksumjava.io.IOException - when the file passed in does not existjava.security.NoSuchAlgorithmException - when the SHA1 algorithm is
not availablepublic static java.lang.String getChecksum(java.lang.String algorithm,
byte[] bytes)
algorithm - the algorithm to use (md5, sha1, etc.) to calculate the
message digestbytes - the bytes to generate the MD5 checksumpublic static java.lang.String getMD5Checksum(java.lang.String text)
text - the text to generate the MD5 checksumpublic static java.lang.String getSHA1Checksum(java.lang.String text)
text - the text to generate the SHA1 checksumpublic static java.lang.String getSHA256Checksum(java.lang.String text)
text - the text to generate the SHA1 checksumpublic static java.lang.String getHex(byte[] raw)
Converts a byte array into a hex string.
This method was copied from http://www.rgagnon.com/javadetails/java-0596.html
raw - a byte arrayCopyright© 2012-21 Jeremy Long. All Rights Reserved.