@@ -0,0 +1,3493 @@
+/*%0ACopyright (c) 2013, Colorado State University%0AAll rights reserved.%0A%0ARedistribution and use in source and binary forms, with or without modification,%0Aare permitted provided that the following conditions are met:%0A%0A1. Redistributions of source code must retain the above copyright notice, this%0A   list of conditions and the following disclaimer.%0A2. Redistributions in binary form must reproduce the above copyright notice,%0A   this list of conditions and the following disclaimer in the documentation%0A   and/or other materials provided with the distribution.%0A%0AThis software is provided by the copyright holders and contributors %22as is%22 and%0Aany express or implied warranties, including, but not limited to, the implied%0Awarranties of merchantability and fitness for a particular purpose are%0Adisclaimed. In no event shall the copyright holder or contributors be liable for%0Aany direct, indirect, incidental, special, exemplary, or consequential damages%0A(including, but not limited to, procurement of substitute goods or services;%0Aloss of use, data, or profits; or business interruption) however caused and on%0Aany theory of liability, whether in contract, strict liability, or tort%0A(including negligence or otherwise) arising in any way out of the use of this%0Asoftware, even if advised of the possibility of such damage.%0A*/%0A%0Apackage mendel.util;%0A%0Aimport java.math.BigInteger;%0Aimport java.security.MessageDigest;%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0A/**%0A * Provides convenience functions for dealing with MessageDigest algorithms.%0A *%0A * @author malensek%0A */%0Apublic class Checksum %7B%0A%0A    private static final Logger logger = Logger.getLogger(%22galileo%22);%0A%0A    private MessageDigest md;%0A%0A    /**%0A     * Initializes a new Checksum generator using the default SHA-1 algorithm.%0A     */%0A    public Checksum() %7B%0A        /* We assume the %22SHA1%22 algorithm is always available */%0A        try %7B%0A            md = MessageDigest.getInstance(%22SHA1%22);%0A        %7D catch (NoSuchAlgorithmException e) %7B%0A            logger.log(Level.SEVERE,%0A                    %22SHA1 message digest algorithm not found!%22, e);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Initializes a new Checksum generator using the specified algorithm.%0A     *%0A     * @param algorithm algorithm to use to generate checksums.%0A     */%0A    public Checksum(String algorithm)%0A    throws NoSuchAlgorithmException %7B%0A        md = MessageDigest.getInstance(algorithm);%0A    %7D%0A%0A    /**%0A     * Produce a checksum/hashsum of a given block of data.%0A     *%0A     * @param bytes data bytes to checksum.%0A     *%0A     * @return checksum as a byte array.%0A     */%0A    public byte%5B%5D hash(byte%5B%5D bytes) %7B%0A        return md.digest(bytes);%0A    %7D%0A%0A    /**%0A     * Convert a hash to a hexidecimal String.%0A     *%0A     * @param hash the hash value to convert%0A     *%0A     * @return zero-padded hex String representation of the hash.%0A     */%0A    public String hashToHexString(byte%5B%5D hash) %7B%0A        BigInteger bigInt = new BigInteger(1, hash);%0A%0A        /* Determine the max number of hex characters the digest will produce */%0A        long targetLen = md.getDigestLength() * 2;%0A%0A        /* Return a formatted zero-padded String */%0A        return String.format(%22%250%22 + targetLen + %22x%22, bigInt);%0A    %7D%0A%0A    /**%0A     * Retrieves the MessageDigest instance used by this Checksum generator.%0A     *%0A     * @return the Checksum instance MessageDigest.%0A     */%0A    public MessageDigest getMessageDigest() %7B%0A        return md;%0A    %7D%0A%7D%0A

Add checksum utitility