[System] Check the md5 value of the file

Checking md5 can confirm whether the file has been tampered with or whether the download is complete. There are many small tools on the Internet, but in fact, the commands that come with the system can also be checked.

1. Windows system

The Windows system comes with the certutil command which contains the command to view the file hash, and you can execute the certutil command in the cmd window

命令:certutil -hashfile 文件 算法

举例:certutil -hashfile "E:\wallet_backend.sql" MD5

支持算法:MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512

2. Linux system

The Linux system also has its own command to obtain the file md5, you can use the md5sum command in the terminal

命令:md5sum 文件
举例:md5sum /home/fyzc/nohup.out

3.Python

In addition, there are packages for viewing hash in various languages, such as Python's

import hashlib


def calculate_md5_for_str(text):
    md5 = hashlib.md5()
    md5.update(str(text).encode("utf-8"))
    return md5.hexdigest()


def calculate_md5_for_file(file_name):
    m = hashlib.md5()
    with open(file_name, 'rb') as f:
        while True:
            data = f.read(4096)
            if not data:
                break
            m.update(data)

    return m.hexdigest()


if __name__ == '__main__':
    print(calculate_md5_for_str("hello world"))
    print(calculate_md5_for_file(r"E:\wallet_backend.sql"))

Guess you like

Origin blog.csdn.net/qq_39147299/article/details/127755156