public static String generateHash(File f, String hashAlgorithm) {

      MessageDigest md;
      FileInputStream fis;
      int nread;
      BigInteger bi;
      byte[] mdBytes;
      byte[] dataBytes;

      try {
         // Create a temporary array of bytes to read into
         dataBytes = new byte[1024];
         // Create a message digester of hash type
         md = MessageDigest.getInstance(hashAlgorithm);
         // Create a input stream for our file
         fis = new FileInputStream(f);

         // Read all the file's bytes into the hasher
         while ((nread = fis.read(dataBytes)) > 0) {
            md.update(dataBytes, 0, nread);
         }

         // Digest the bytes
         mdBytes = md.digest();

         // Make an int out of the byte array
         bi = new BigInteger(1, mdBytes);

         // Return our converted string
         return bi.toString(16);

      } catch (NoSuchAlgorithmException e) {
         System.out.println("Algorithm is not supported!");
      } catch (IOException e) {
         System.out.println("Error generating hash");
      }

      return "";
   }