Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of calculating file MD5 Checksum

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report