- MD5 (Message Digest) is a technique for verifying data integrity for a file.
- 128 bit key is used for hashing and producing the MD5 output.
Project Structure:-
Test MD5 Code:-
package com.sandeep.md.gen;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5GeneratorTest {
/**
* @param args
*/
public static void main(String[] args) {
InputStream ins = null;
try {
MessageDigest medigest =MessageDigest.getInstance("MD5");
ins = new FileInputStream("sandeep-text.txt");
ins = new DigestInputStream(ins, medigest);
byte[] digestData = medigest.digest();
System.out.println(digestData);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally{
try {
ins.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Output:-
[B@16cd7d5