[Python] python使用sha1加密方法验证文件的有效性 →→→→→进入此内容的聊天室

来自 , 2019-10-31, 写在 Python, 查看 155 次.
URL http://www.code666.cn/view/f18224a1
  1. import hashlib  
  2. hash_new = hashlib.sha1() #或hashlib.md5()  
  3. with open('driver.xml.tar.bz2','rb') as fp: #打开文件,一定要以二进制打开  
  4.     while True:  
  5.         data = fp.read() #读取文件块  
  6.         if not data: #直到读完文件  
  7.             break  
  8.         hash_new.update(data)  
  9. hash_value = hash_new.hexdigest() #生成40位(sha1)或32位(md5)的十六进制字符串  
  10. print hash_value
  11. #//python/7141

回复 "python使用sha1加密方法验证文件的有效性"

这儿你可以回复上面这条便签

captcha