In this article i explain about generating a hash for a file in Java.
We make use of "java.security.*" 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
refer Java API at
http://java.sun.com/j2se/1.4.2/docs/api/java/security/MessageDigest.html
You could use the following org.apache.commons.codec.digest.DigestUtils.md5Hex(inputstream)
ReplyDeletehttp://commons.apache.org/codec/apidocs/org/apache/commons/codec/digest/DigestUtils.html