sha1,256,512 on files

Paul Rubin http
Wed Nov 30 05:20:51 EST 2005


"durumdara at mailpont.hu" <durumdara at mailpont.hu> writes:
> I see that Python supports the sha-1. But I need to make sha value in
> big files to (swap file, iso-s, etc.). Possible that file size more
> than 2 GB, so  I cannot read as string...
> How to get the sha value of a file ?

Use the sha.update method.  Something like:
  ctx = sha.new()
  while True:
    x = f.read(16384)
    if not x: break
    ctx.update(x)
  hash = ctx.digest()

> How to generate sha-256, or sha-512 values ?

There are some modules around for this.  Unless you're trying to
interoperate with something that needs them, or have some other reason
to want them, I wouldn't bother.



More information about the Python-list mailing list