Rex Rex - 1 year ago 121
Python Question

sha256 result dosen't change

First time using sha256. I'm using windows and puthon2.7.

With this code, the result always equal to "4aa6892909e369933b9f1babc10519121e2dfd1042551f6b9bdd4eae51f1f0c2"

what is wrong?

def signning(self,D_path):
BUF_SIZE = 65536
hashed = hashlib.sha256()

with open(D_path, 'rb') as f:
while True:
data =
if not data:

hashed_D = hashed.hexdigest()
print hashed_D

Answer Source

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


for i in range(5):
    data = ''.join(random.choice(string.ascii_uppercase + string.digits)
                   for _ in range(10))

    hashed = hashlib.sha256()
    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 ;)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download