第一次使用sha256。
使用此代码,结果始终等于
4aa6892909e369933b9f1babc10519121e2dfd1042551f6b9bdd4eae51f1f0c2
出了什么问题?
def signning(self,D_path):
BUF_SIZE = 65536
hashed = hashlib.sha256()
with open(D_path, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
hashed.update(data)
hashed_D = hashed.hexdigest()
print hashed_D
是的,您的代码没有任何问题,这里有一个小例子,显示 hashlib.sha256 是确定性的:
import random
import string
import hashlib
random.seed(1)
for i in range(5):
data = ''.join(random.choice(string.ascii_uppercase + string.digits)
for _ in range(10))
hashed = hashlib.sha256()
hashed.update(data)
print data, "->", hashed.hexdigest()
一遍又一遍地运行这个脚本,你会得到相同的输出,因为输入总是相同的;)
def 签名(self,D_path): BUF_大小 = 65536 散列 = hashlib.sha256()
with open(D_path, 'rb') as f:
while True:
data = f.read(BUF_SIZE)
if not data:
break
hashed.update(data)
hashed_D = hashed.hexdigest()
print hashed_D