md5 check
Chris Angelico
rosuav at gmail.com
Thu Apr 19 04:16:43 EDT 2012
On Thu, Apr 19, 2012 at 5:46 PM, contro opinion <contropinion at gmail.com> wrote:
>>>> import hashlib
>
>>>> f=open('c:\gpg4win-2.1.0.exe','rb')
>>>> print hashlib.md5(f.read()).hexdigest()
> ad6245f3238922bb7afdc4a6d3402a65
>>>> print hashlib.sha1(f.read()).hexdigest()
> da39a3ee5e6b4b0d3255bfef95601890afd80709
>
> i get it with md5,why the sha1 is wrong?
>
> the sha1 right is
>
> f619313cb42241d6837d20d24a814b81a1fe7f6d
After you read from the file, you can't read that content again
without rewinding it. What you got there is this:
>>> hashlib.sha1(b'').hexdigest()
'da39a3ee5e6b4b0d3255bfef95601890afd80709'
Try again, but without getting the md5 first.
ChrisA
More information about the Python-list
mailing list