Package org.owasp.dependencycheck.utils
Class Checksum
- java.lang.Object
-
- org.owasp.dependencycheck.utils.Checksum
-
public final class Checksum extends java.lang.ObjectIncludes methods to generate the MD5 and SHA1 checksum.- Version:
- $Id: $Id
- Author:
- Jeremy Long
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringgetChecksum(java.lang.String algorithm, byte[] bytes)Calculates the MD5 checksum of a specified bytes.static java.lang.StringgetChecksum(java.lang.String algorithm, java.io.File file)Creates the cryptographic checksum of a given file using the specified algorithm.static java.lang.StringgetHex(byte[] raw)Converts a byte array into a hex string.static java.lang.StringgetMD5Checksum(java.io.File file)Calculates the MD5 checksum of a specified file.static java.lang.StringgetMD5Checksum(java.lang.String text)Calculates the MD5 checksum of the specified text.static java.lang.StringgetSHA1Checksum(java.io.File file)Calculates the SHA1 checksum of a specified file.static java.lang.StringgetSHA1Checksum(java.lang.String text)Calculates the SHA1 checksum of the specified text.static java.lang.StringgetSHA256Checksum(java.io.File file)Calculates the SH256 checksum of a specified file.static java.lang.StringgetSHA256Checksum(java.lang.String text)Calculates the SHA256 checksum of the specified text.
-
-
-
Method Detail
-
getChecksum
public static java.lang.String getChecksum(java.lang.String algorithm, java.io.File file) throws java.security.NoSuchAlgorithmException, java.io.IOExceptionCreates 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:
java.io.IOException- when the file does not existjava.security.NoSuchAlgorithmException- when an algorithm is specified that does not exist
-
getMD5Checksum
public static java.lang.String getMD5Checksum(java.io.File file) throws java.io.IOException, java.security.NoSuchAlgorithmExceptionCalculates 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:
java.io.IOException- when the file passed in does not existjava.security.NoSuchAlgorithmException- when the MD5 algorithm is not available
-
getSHA1Checksum
public static java.lang.String getSHA1Checksum(java.io.File file) throws java.io.IOException, java.security.NoSuchAlgorithmExceptionCalculates 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:
java.io.IOException- when the file passed in does not existjava.security.NoSuchAlgorithmException- when the SHA1 algorithm is not available
-
getSHA256Checksum
public static java.lang.String getSHA256Checksum(java.io.File file) throws java.io.IOException, java.security.NoSuchAlgorithmExceptionCalculates 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:
java.io.IOException- when the file passed in does not existjava.security.NoSuchAlgorithmException- when the SHA1 algorithm is not available
-
getChecksum
public static java.lang.String getChecksum(java.lang.String algorithm, byte[] bytes)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
public static java.lang.String getMD5Checksum(java.lang.String text)
Calculates the MD5 checksum of the specified text.- Parameters:
text- the text to generate the MD5 checksum- Returns:
- the hex representation of the MD5
-
getSHA1Checksum
public static java.lang.String getSHA1Checksum(java.lang.String text)
Calculates the SHA1 checksum of the specified text.- Parameters:
text- the text to generate the SHA1 checksum- Returns:
- the hex representation of the SHA1
-
getSHA256Checksum
public static java.lang.String getSHA256Checksum(java.lang.String text)
Calculates the SHA256 checksum of the specified text.- Parameters:
text- the text to generate the SHA1 checksum- Returns:
- the hex representation of the SHA1
-
getHex
public 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
- Parameters:
raw- a byte array- Returns:
- the hex representation of the byte array
-
-