Friday, April 23, 2010

Generate Hash of a file: Java

I google'ed/bing'ed a lot to find articles on generating a hash of a file and found none. So, i decided to write one myself.

In this article i explain about generating a hash for a file in Java.

We make use of "*" API classes to achieve the task.

In the following program i am generating the hash of the java source of this program (it need not be so, you can generate hash for any file).

The method

getInstance in 

MessageDigest class takes name of the hashing technique/Algorithm as a paramter

refer Java API at

1 comment:

  1. You could use the following org.apache.commons.codec.digest.DigestUtils.md5Hex(inputstream)