开发者

MD5 hash differences between Python and other file hashers

I have been doing a bit of programming in Python (still a n00b at it) and came across something odd. I made a small program to find the MD5 hash of a filename passed to it on the command line. I used a function I found here on SO. When I ran it against a file, I got a hash "58a...113". But when I ran Microsoft's FCIV or the md5sum.py in \Python26\Tools\Scripts\, I get a different hash, "591...ae6". The actual hashing part of the md5sum.py in Scripts is

m = md5.new()
while 1:
    data = fp.read(bufsize)
    if not data:
        break
    m.update(data)
out.write('%s %s\n'开发者_如何学Python % (m.hexdigest(), filename))

This looks functionally identical to the code in the function given in the other answer... What am I missing? (This is my first time posting to stackoverflow, please let me know if I am doing it wrong.)


Already resolved in comments, but in case anyone wants to give me points... ;)

Open your file in binary mode!

f = open(path, 'rb')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜