FAQ
Hello list-members

i am in the process of writing a python script to backup my data. Now I
would like to implement md5/sha1 hashes.

# do md5 fingerprinting
if config.get("global", "crc") == "md5":
m = md5.new()
# open the file
f = open(fname, "rb")
while 1:
block = f.read(1024*1024)
if not block:
break
# generate the hash
m.update(block)
f.close()

# write the results properly formated to a file
fd = file(fname + ".md5", "w")
fd.write(m.hexdigest())
fd.write(" " + fname + "\n")
fd.close()


mguentert at uranos > md5sum -c backup.tar.bz2.md5
/fileservice/temp/backup.tar.bz2: FAILED
md5sum: WARNING: 1 of 1 computed checksum did NOT match

mguentert at uranos > cat backup.tar.bz2.md5
d41d8cd98f00b204e9800998ecf8427e /fileservice/temp/backup.tar.bz2

so the format should be okay, but whats wrong with my piece of code?!

Greetings

--
Mit freundlichen Gr??en

Matthias G?ntert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-list/attachments/20060326/164035b1/attachment.pgp

Search Discussions

  • Felipe Almeida Lessa at Mar 26, 2006 at 2:59 pm

    Em Dom, 2006-03-26 ?s 16:56 +0200, Matthias G?ntert escreveu:
    so the format should be okay, but whats wrong with my piece of code?!
    It looks ok for me. What does md5sum gives as the sum?

    --
    Felipe.
  • Adam DePrince at Mar 26, 2006 at 4:48 pm
    What do you get when you type

    md5sum backup.tar.bz2?

    - Adam
    On Sun, 2006-03-26 at 16:56 +0200, Matthias G?ntert wrote:
    Hello list-members

    i am in the process of writing a python script to backup my data. Now I
    would like to implement md5/sha1 hashes.

    # do md5 fingerprinting
    if config.get("global", "crc") == "md5":
    m = md5.new()
    # open the file
    f = open(fname, "rb")
    while 1:
    block = f.read(1024*1024)
    if not block:
    break
    # generate the hash
    m.update(block)
    f.close()

    # write the results properly formated to a file
    fd = file(fname + ".md5", "w")
    fd.write(m.hexdigest())
    fd.write(" " + fname + "\n")
    fd.close()


    mguentert at uranos > md5sum -c backup.tar.bz2.md5
    /fileservice/temp/backup.tar.bz2: FAILED
    md5sum: WARNING: 1 of 1 computed checksum did NOT match

    mguentert at uranos > cat backup.tar.bz2.md5
    d41d8cd98f00b204e9800998ecf8427e /fileservice/temp/backup.tar.bz2

    so the format should be okay, but whats wrong with my piece of code?!

    Greetings

    --
    http://mail.python.org/mailman/listinfo/python-list
  • Matthias Güntert at Mar 26, 2006 at 5:31 pm

    On Sun, 2006-03-26 at 11:48 -0500, Adam DePrince wrote:
    What do you get when you type

    md5sum backup.tar.bz2?
    it is working. Don't know what went wrong. But now I have another
    question: How am I able to execute an external program, like mysqldump?
    I had a look into the mysql module it didn't fit my needs.

    --
    Mit freundlichen Gr??en

    Matthias G?ntert
  • Adam DePrince at Mar 26, 2006 at 4:57 pm

    On Sun, 2006-03-26 at 16:56 +0200, Matthias G?ntert wrote:
    Hello list-members

    i am in the process of writing a python script to backup my data. Now I
    would like to implement md5/sha1 hashes.

    # do md5 fingerprinting
    if config.get("global", "crc") == "md5":
    m = md5.new()
    # open the file
    f = open(fname, "rb")
    while 1:
    block = f.read(1024*1024)
    if not block:
    break
    # generate the hash
    m.update(block)
    f.close()

    # write the results properly formated to a file
    fd = file(fname + ".md5", "w")
    fd.write(m.hexdigest())
    fd.write(" " + fname + "\n")
    fd.close()


    mguentert at uranos > md5sum -c backup.tar.bz2.md5
    /fileservice/temp/backup.tar.bz2: FAILED
    md5sum: WARNING: 1 of 1 computed checksum did NOT match

    mguentert at uranos > cat backup.tar.bz2.md5
    d41d8cd98f00b204e9800998ecf8427e /fileservice/temp/backup.tar.bz2

    Hey, I found an md5 collision for your file!
    import md5
    md5.new().hexdigest()
    'd41d8cd98f00b204e9800998ecf8427e'
    >>>
    [adam at localhost Include]$ md5sum # hit ^d at start
    d41d8cd98f00b204e9800998ecf8427e -

    Your file was empty when scanned.

    Without more information, I'd say that your file was empty when you ran
    your python code.

    But your code does work ...

    import md5
    m = md5.new()
    # open the file
    fname="Python-2.4.2.tar.bz2"
    f = open(fname, "rb" )
    while 1:
    block = f.read(1024*1024)
    if not block:
    break
    # generate the hash
    m.update(block)
    f.close()
    fd = file(fname + ".md5", "w")
    fd.write(m.hexdigest())
    fd.write(" " + fname + "\n")
    fd.close()

    [adam at localhost ~]$ python test2.py
    [adam at localhost ~]$ md5sum -c Python-2.4.2.tar.bz2.md5
    Python-2.4.2.tar.bz2: OK

    - Adam

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMar 26, '06 at 2:56p
activeMar 26, '06 at 5:31p
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase