|
|
|
|
|
|
| Author |
Message |
Matthias Güntert *nix forums beginner
Joined: 26 Mar 2006
Posts: 2
|
Posted: Sun Mar 26, 2006 2:56 pm Post subject:
wired md5 hashing problem
|
|
|
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@uranos > md5sum -c backup.tar.bz2.md5
/fileservice/temp/backup.tar.bz2: FAILED
md5sum: WARNING: 1 of 1 computed checksum did NOT match
mguentert@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 |
|
| Back to top |
|
 |
Felipe Almeida Lessa *nix forums Guru Wannabe
Joined: 11 Feb 2006
Posts: 147
|
Posted: Sun Mar 26, 2006 2:59 pm Post subject:
Re: wired md5 hashing problem
|
|
|
Em Dom, 2006-03-26 às 16:56 +0200, Matthias Güntert escreveu:
| Quote: | 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. |
|
| Back to top |
|
 |
adam.deprince@gmail.com *nix forums beginner
Joined: 24 Mar 2006
Posts: 21
|
Posted: Sun Mar 26, 2006 4:48 pm Post subject:
Re: wired md5 hashing problem
|
|
|
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:
| Quote: | 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@uranos > md5sum -c backup.tar.bz2.md5
/fileservice/temp/backup.tar.bz2: FAILED
md5sum: WARNING: 1 of 1 computed checksum did NOT match
mguentert@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 |
|
|
| Back to top |
|
 |
adam.deprince@gmail.com *nix forums beginner
Joined: 24 Mar 2006
Posts: 21
|
Posted: Sun Mar 26, 2006 4:57 pm Post subject:
Re: wired md5 hashing problem
|
|
|
On Sun, 2006-03-26 at 16:56 +0200, Matthias Güntert wrote:
| Quote: | 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@uranos > md5sum -c backup.tar.bz2.md5
/fileservice/temp/backup.tar.bz2: FAILED
md5sum: WARNING: 1 of 1 computed checksum did NOT match
mguentert@uranos > cat backup.tar.bz2.md5
d41d8cd98f00b204e9800998ecf8427e /fileservice/temp/backup.tar.bz2
|
Hey, I found an md5 collision for your file!
| Quote: | import md5
md5.new().hexdigest()
'd41d8cd98f00b204e9800998ecf8427e'
[adam@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@localhost ~]$ python test2.py
[adam@localhost ~]$ md5sum -c Python-2.4.2.tar.bz2.md5
Python-2.4.2.tar.bz2: OK
- Adam |
|
| Back to top |
|
 |
Matthias Güntert *nix forums beginner
Joined: 26 Mar 2006
Posts: 2
|
Posted: Sun Mar 26, 2006 5:31 pm Post subject:
Re: wired md5 hashing problem
|
|
|
On Sun, 2006-03-26 at 11:48 -0500, Adam DePrince wrote:
| Quote: |
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 |
|
| Back to top |
|
 |
Paul Rubin *nix forums Guru
Joined: 28 Feb 2005
Posts: 1197
|
Posted: Sun Mar 26, 2006 8:30 pm Post subject:
Re: wired md5 hashing problem
|
|
|
Matthias Güntert <MatzeGuentert@gmx.de> writes:
| Quote: | i am in the process of writing a python script to backup my data. Now I
would like to implement md5/sha1 hashes.
|
Try editing as follows: change
| Quote: | f = open(fname, "rb")
while 1:
block = f.read(1024*1024)
if not block:
break
# generate the hash
m.update(block)
f.close()
|
to:
f = open(fname, "rb")
nbytes = 0
while 1:
block = f.read(1024*1024)
nbytes += len(block)
if not block:
break
# generate the hash
m.update(block)
f.close()
print '%d bytes processed'
As Adam DePrince noticed, the md5 checksum you generated was that of
an empty file. So the above should tell you whether you're actually
processing any input; if you don't get the expected number of bytes,
debug from there. |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Wed Dec 03, 2008 1:39 am | All times are GMT
|
|
Electricity Suppliers | Debt Consolidation | Debt Consolidation | WoW Gold | Shares
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|