官术网_书友最值得收藏!

How it works...

This section will explain the steps that have been provided in the previous section:

  • In step 1, we import hashlib, a standard Python library for hash computation. We also specify the file we will be hashing—in this case, the file is python-3.7.2-amd64.exe.
  • In step 2, we instantiate an md5 object and an sha256 object and specify the size of the chunks we will be reading.
  • In step 3, we utilize the .update(data) method. This method allows us to compute the hash incrementally because it computes the hash of the concatenation. In other words, hash.update(a) followed by hash.update(b) is equivalent to hash.update(a+b).
  • In step 4, we print out the hashes in hexadecimal digits.

We can also verify that our computation is consistent with the hash calculations given by other sources, such as VirusTotal and the official Python website. The MD5 hash is displayed on the Python web page (https://www.python.org/downloads/release/python-372/):

The SHA256 hash is computed by uploading the file to VirusTotal (https://www.virustotal.com/gui/home):

主站蜘蛛池模板: 灵寿县| 莎车县| 齐河县| 得荣县| 桂林市| 井冈山市| 苏尼特左旗| 太白县| 高邑县| 永泰县| 苍梧县| 巴彦县| 安阳市| 社旗县| 垫江县| 德令哈市| 鹤岗市| 翼城县| 阳城县| 湖北省| 巴南区| 双柏县| 三原县| 额敏县| 托克逊县| 天气| 赞皇县| 榆社县| 开封市| 东海县| 承德市| 静宁县| 灌阳县| 西丰县| 白水县| 曲阜市| 和田市| 额敏县| 德清县| 焉耆| 磴口县|