Jay K. answered 01/29/20
Tutor
5.0
(98)
Senior Java Developer with 20 Years of Professional Experience
Try using the java.security.MessageDigest Class. For example:
public void givenFile_generatingChecksum_thenVerifying()
throws NoSuchAlgorithmException, IOException {
String filename = "src/test/resources/test_md5.txt";
String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3";
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(Files.readAllBytes(Paths.get(filename)));
byte[] digest = md.digest();
String myChecksum = DatatypeConverter
.printHexBinary(digest).toUpperCase();
assertThat(myChecksum.equals(checksum)).isTrue();
}
Source: https://www.baeldung.com/java-md5