Class Checksum

java.lang.Object
org.owasp.dependencycheck.utils.Checksum

public final class Checksum extends Object
Includes methods to generate the MD5 and SHA1 checksum.
Version:
$Id: $Id
Author:
Jeremy Long
  • 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 checksum
      file - the file to calculate the checksum for
      Returns:
      the checksum
      Throws:
      IOException - when the file does not exist
      NoSuchAlgorithmException - when an algorithm is specified that does not exist
    • getMD5Checksum

      public static String getMD5Checksum(File file) throws IOException, NoSuchAlgorithmException
      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 exist
      NoSuchAlgorithmException - when the MD5 algorithm is not available
    • getSHA1Checksum

      public static String getSHA1Checksum(File file) throws IOException, NoSuchAlgorithmException
      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 exist
      NoSuchAlgorithmException - when the SHA1 algorithm is not available
    • getSHA256Checksum

      public static String getSHA256Checksum(File file) throws IOException, NoSuchAlgorithmException
      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 exist
      NoSuchAlgorithmException - when the SHA1 algorithm is not available
    • getChecksum

      public static String getChecksum(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 digest
      bytes - the bytes to generate the MD5 checksum
      Returns:
      the hex representation of the MD5 hash
    • getMD5Checksum

      public static String getMD5Checksum(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 String getSHA1Checksum(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 String getSHA256Checksum(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 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