md5 check

Peter Otten __peter__ at web.de
Thu Apr 19 03:59:48 EDT 2012


contro opinion 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?

You get the checksum for the empty string "" which is what f.read() returns 
on the second time. Try

data = open('c:\gpg4win-2.1.0.exe','rb').read()
print  hashlib.md5(data).hexdigest()
print  hashlib.sha1(data).hexdigest()
 
> the sha1 right is
> 
> f619313cb42241d6837d20d24a814b81a1fe7f6d

I'm sure you can solve simple problems like the above yourself; please spend 
a few more minutes on finding the cause before you post here.




More information about the Python-list mailing list