First time using sha256. I'm using windows and puthon2.7.
With this code, the result always equal to "4aa6892909e369933b9f1babc10519121e2dfd1042551f6b9bdd4eae51f1f0c2"
what is wrong?
BUF_SIZE = 65536
hashed = hashlib.sha256()
with open(D_path, 'rb') as f:
data = f.read(BUF_SIZE)
if not data:
hashed_D = hashed.hexdigest()
Yeah, there is nothing wrong with your code, here's a little example showing that hashlib.sha256 is deterministic:
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()
Run this script over and over and you'll be getting the same output cos the input is always the same ;)