Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate Hash of any file in java?

Tags:

java

hash

How to generate Hash value of any type of file (.doc,.docx,*.pdf, etc...) in java?

like image 776
Sanju Avatar asked Feb 03 '11 06:02

Sanju


People also ask

How do you generate a hash key in Java?

MD5 Message Digest Algorithm Here we have used the digest() method of the MessageDigest class from the java. security package to create the MD5 hash in bytes and then converted those bytes to hex format to generate the hash as text.

How do I create a hash file?

First we'll explain the simplest way to use it: via Windows File Explorer. In Windows File Explorer select the files you want the hash values calculated for, click the right mouse button, and select Calculate Hash Value, then select the appropriate hash type from the pop-up sub-menu (e.g. MD5).


1 Answers

There is a related answer posted here Getting a File's MD5 Checksum in Java

You may look into "Real's How To" Here and use your desired hashing algorithm like this

String myHash = "MD5"; // or "SHA-1" or "SHA-256"
MessageDigest complete = MessageDigest.getInstance(myHash);
like image 134
Nishant Avatar answered Oct 07 '22 01:10

Nishant