Help getting the md5 module to work

Amy G amy-g-art at cox.net
Sat Mar 20 03:01:48 EST 2004


I have never used the md5 module that python offers... but after reading
this post I thought I would try it out.

>>> n = md5.new()
>>> n.update("help")
>>> n.hexdigest()
'657f8b8da628ef83cf69101b6817150a'

But I run FreeBSD 5.0 and when I execute
$ echo help | openssl md5
45b758a4f518f3ff31363696132f5f5a

What gives?  What am I missing here?

Thanks in advance for shedding some light on my "easy" question.


Carl Banks" <imbosol at aerojockey.invalid> wrote in message
news:m1O6c.25774$P45.20864 at fe1.columbus.rr.com...
> Grumfish wrote:
> > I'm trying to use the md5 module but it gives me a different result from
> > what other programs give. This is the code I have and the result from
> > hexdigest() never matches what I expect. Its probably something stupid
> > but its driving me crazy.
> >
> > f = file (filename, "r")
> > m = md5.new()
> > data = f.read (CHUNK_SIZE)
> > while data != "":
> >        m.update (data)
> >        data = f.read (CHUNK_SIZE)
>
>
> I'll wager this is happening on Windows.  When reading data in text
> mode on Windows, Python converts "\r\n" sequence to "\n".  You need to
> open the file in binary mode.  Try changing the first line to:
>
>     f = file(filename,"rb")
>
>
>
>
> -- 
> CARL BANKS                      http://www.aerojockey.com/software
> "If you believe in yourself, drink your school, stay on drugs, and
> don't do milk, you can get work."
>           -- Parody of Mr. T from a Robert Smigel Cartoon





More information about the Python-list mailing list