【系统】查看文件的md5值

查看md5可以确认文件是否被篡改或者是否下载完成,网上有很多小工具,但实际上系统自带的命令也能查看。

1.Windows系统

Windows系统自带有certutil命令里面包含了查看文件哈希的命令,可以在cmd窗口执行certutil命令

命令:certutil -hashfile 文件 算法

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

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

2.Linux系统

Linux系统也有自带的获取文件md5的命令,可以在终端使用md5sum命令

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

3.Python

另外各种语言都有查看hash的包,比如说Python的

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"))

猜你喜欢

转载自blog.csdn.net/qq_39147299/article/details/127755156
今日推荐