Python中文
首页
教程
问答
标签
搜索
登录
注册
为什么Python计算的“hashlib.sha1”和“git hash-object”对于一个文件来说不同?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在计算一个文件的SHA-1值。</p> <p>我编造了这个剧本:</p> <pre><code>def hashfile(filepath): sha1 = hashlib.sha1() f = open(filepath, 'rb') try: sha1.update(f.read()) finally: f.close() return sha1.hexdigest() </code></pre> <p>对于一个特定的文件,我得到这个散列值:<br/> <code>8c3e109ff260f7b11087974ef7bcdbdc69a0a3b9</code><br/> 但是当我用git hash对象计算值时,我得到这个值:<code>d339346ca154f6ed9e92205c3c5c38112e761eb7</code></p> <p>它们为什么不同?我是做错了什么,还是我可以忽略两者的区别?</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>git计算散列如下:</p> <pre><code>sha1("blob " + filesize + "\0" + data) </code></pre> <p><a href="https://stackoverflow.com/questions/552659/assigning-git-sha1s-without-git">Reference</a></p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
得到媒体:缩略图url从rss源
3 回答
得到对数正态随机数给定log10均值和log10标准差
7 回答
得到工作,波斯特不
6 回答
得到左半积和右半积的绝对差最小的元素
10 回答
得到幻数错误?
2 回答
得到异常错误“线程中的异常-1(最有可能在解释器关闭期间引发)”,它使用Parami
9 回答
得到循环
6 回答
得到德语的语法变化
5 回答
得到我认为是好的结果,但还不够
9 回答
得到截断svd.transform()返回float16而不是float64
8 回答
得到所有不相交的集合的并集
4 回答
得到所有函数求值组合的矩阵
7 回答
得到扭曲延迟取消错误当使用刮痧时
4 回答
得到控制台.log使用Selenium python从Chrome输出一次,然后调用第二次为空
5 回答
得到操作系统环境通过NSSM运行Python
9 回答
得到数学方程中的表达式
8 回答
得到数据库结构属性
10 回答
得到整数的后三位
3 回答
得到整数的第n位精度
2 回答
得到最低落的reddit评论
2 回答