Python file Hash (MD5,SHA1)

Source: Internet
Author: User
Tags sha1

Using Python for file hash calculations there are two points to note:

1, file Open the way must be binary mode, both open the file when using B mode, or hash calculation is based on the text that will get the wrong file hash (online to see someone said to have encountered a Python hash calculation error in most is due to this cause).

2, for MD5 if you need 16-bit (bytes) value then call the object's Digest () and hexdigest () default is 32 bits (bytes), the same SHA1 digest () and hexdigest () respectively produce 20 bits (bytes) and 40 bits ( bytes) hash value

Python file Hash (MD5,SHA1)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.