首页 > 其他 > 详细

求文件的hash值(基于SHA3的Hash)

时间:2018-12-21 22:02:20      阅读:128      评论:0      收藏:0      [点我收藏+]
import hashlib
import tkinter
from tkinter import filedialog
import pyperclip

def fileHash(fileName):
    m=hashlib.sha384()                    #可以根据需求来选择md5,256,384,512
    with open(fileName,rb) as file:     #‘rb‘以二进制的格式打开一个文件
        while True:
            data=file.read(4096)      #read() 方法用于从文件读取指定的字节数,如果未给定或为负则读取所有。
            if not data:
                break
            m.update(data)            #Continue hashing of a message by consuming the next chunk of data.
    return m.hexdigest()

def chooseFile():
    root=tkinter.Tk()    # 创建一个Tkinter.Tk()实例
    root.withdraw()       # 将Tkinter.Tk()实例隐藏
    filename=tkinter.filedialog.askopenfilename(title=u请选择文件)     # 选择打开什么文件,返回文件名
    return filename
    
def pyperClip():
    filename=chooseFile()
    filehash=fileHash(filename)
    pyperclip.copy(filehash)
    print(filehash)

if __name__ == "__main__":
    pyperClip()

 

求文件的hash值(基于SHA3的Hash)

原文:https://www.cnblogs.com/Guhongying/p/10158797.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!