Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.owasp.dependencycheck.utils
Class Checksum

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

    public class Checksum

extends Object

Includes methods to generate the MD5 and SHA1 checksum. This code was copied from Real's How To. It has been slightly modified. Written and compiled by Réal Gagnon ©1998-2012

Author:
  Real's How To: http://www.rgagnon.com/javadetails/java-0416.html

Constructor Summary
`Checksum()`

Method Summary
`static byte[]` | `getChecksum(String algorithm, File file)` Creates the cryptographic checksum of a given file using the specified algorithm.
`static String` | `getHex(byte[] raw)` Converts a byte array into a hex string.
`static String` | `getMD5Checksum(File file)` Calculates the MD5 checksum of a specified file.
`static String` | `getSHA1Checksum(File file)` Calculates the SHA1 checksum of a specified file.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Checksum

    public Checksum()

Method Detail

### getChecksum

    public static byte[] getChecksum(String algorithm,
                                     File file)
                              throws NoSuchAlgorithmException,
                                     IOException

  Creates the cryptographic checksum of a given file using the specified algorithm.

  This algorithm was copied and heavily modified from Real's How To: http://www.rgagnon.com/javadetails/java-0416.html

  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

### 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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2012-2013 OWASP. All Rights Reserved.