sha256 result dosen't change
<p>First time using sha256.</p>

<p>With this code, the result always equals to <code>4aa6892909e369933b9f1babc10519121e2dfd1042551f6b9bdd4eae51f1f0c2</code></p>

<p>what is wrong?</p>

<pre><code>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
</code></pre>

<p>Yeah, there is nothing wrong with your code, here's a little example showing that hashlib.sha256 is deterministic:</p>

<pre><code>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, "-&gt;", hashed.hexdigest()
</code></pre>

<p>Run this script over and over and you'll be getting the same output cos the input is always the same ;)</p>

python python-2.7 sha256 sha