Class Checksum
java.lang.Object
org.owasp.dependencycheck.utils.Checksum
Includes methods to generate the MD5 and SHA1 checksum.
- Version:
- $Id: $Id
- Author:
- Jeremy Long
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetChecksum(String algorithm, byte[] bytes) Calculates the MD5 checksum of a specified bytes.static StringgetChecksum(String algorithm, File file) Creates the cryptographic checksum of a given file using the specified algorithm.static StringgetHex(byte[] raw) Converts a byte array into a hex string.static StringgetMD5Checksum(File file) Calculates the MD5 checksum of a specified file.static StringgetMD5Checksum(String text) Calculates the MD5 checksum of the specified text.static StringgetSHA1Checksum(File file) Calculates the SHA1 checksum of a specified file.static StringgetSHA1Checksum(String text) Calculates the SHA1 checksum of the specified text.static StringgetSHA256Checksum(File file) Calculates the SH256 checksum of a specified file.static StringgetSHA256Checksum(String text) Calculates the SHA256 checksum of the specified text.
-
Method Details
-
getChecksum
public static String getChecksum(String algorithm, File file) throws NoSuchAlgorithmException, IOException Creates the cryptographic checksum of a given file using the specified algorithm.
- Parameters:
algorithm- the algorithm to use to calculate the checksumfile- the file to calculate the checksum for- Returns:
- the checksum
- Throws:
IOException- when the file does not existNoSuchAlgorithmException- when an algorithm is specified that does not exist
-
getMD5Checksum
Calculates the MD5 checksum of a specified file.- Parameters:
file- the file to generate the MD5 checksum- Returns:
- the hex representation of the MD5 hash
- Throws:
IOException- when the file passed in does not existNoSuchAlgorithmException- when the MD5 algorithm is not available
-
getSHA1Checksum
Calculates the SHA1 checksum of a specified file.- Parameters:
file- the file to generate the MD5 checksum- Returns:
- the hex representation of the SHA1 hash
- Throws:
IOException- when the file passed in does not existNoSuchAlgorithmException- when the SHA1 algorithm is not available
-
getSHA256Checksum
Calculates the SH256 checksum of a specified file.- Parameters:
file- the file to generate the MD5 checksum- Returns:
- the hex representation of the SHA1 hash
- Throws:
IOException- when the file passed in does not existNoSuchAlgorithmException- when the SHA1 algorithm is not available
-
getChecksum
Calculates the MD5 checksum of a specified bytes.- Parameters:
algorithm- the algorithm to use (md5, sha1, etc.) to calculate the message digestbytes- the bytes to generate the MD5 checksum- Returns:
- the hex representation of the MD5 hash
-
getMD5Checksum
-
getSHA1Checksum
-
getSHA256Checksum
-
getHex
Converts a byte array into a hex string.
This method was copied from http://www.rgagnon.com/javadetails/java-0596.html
- Parameters:
raw- a byte array- Returns:
- the hex representation of the byte array
-