Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the methods of calculating file MD5 Checksum

Shulou Source: shulou.com Published: 2022-06-03 11:27:30 11月15日 Update

What are the methods of calculating the file MD5 Checksum? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

What is the purpose of using MD5 CheckSum for files?

In some scenarios, such as file transfer (such as plug-ins, firmware upgrade packages, etc.), MD5 CheckSum is used to check the integrity of the file and detect whether the file has been maliciously tampered with.

On the Apache website, we can see the value of MD5 checksum when we download the file, as shown in the following figure:

Next, we will show several ways for files to generate MD5 (checkSum).

Use java.security.MessageDigest

Where, the following code

You can use the javax.xml.bind.DatatypeConverter method to do this.

Because the characters returned by DatatypeConverter.printHexBinary (digestBytes) are capitalized

So the toLowerCase () method is added to keep it consistent.

Use org.apache.commons.codec.digest.DigestUtils

To complete using commons-codec, the Maven project needs to add dependent packages, such as:

The Java code is as follows:

Use Guava

Add Guava dependency packages, such as:

The Java code is as follows:

Complete code and testing

For the above methods, the complete examples and test code are as follows ~

The test code is as follows:

The code runs as follows:

Compared with the MD5 checkSum of the download file poi-bin-3.16-20170419.zip on the Apache page, we find that it is consistent ~

The answers to the questions about the method of calculating the file MD5 Checksum are shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Tags: File method code question test consistent more help answer easy next easy consistent up and down function content firmware scenario uppercase character Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info Linux OPPO Reno MariaDB