15.2 sha -- SHA message digest algorithm

This module implements the interface to NIST's secure hash algorithm, known as SHA. It is used in the same way as the md5 module: use the new() to create an sha object, then feed this object with arbitrary strings using the update() method, and at any point you can ask it for the digest of the contatenation of the strings fed to it so far. SHA digests are 160 bits instead of 128 bits.

new ([string])
Return a new sha object. If string is present, the method call update(string) is made.

The following values are provided as constants in the module and as attributes of the sha objects returned by new():

Size of the blocks fed into the hash function; this is always 1. This size is used to allow an arbitrary string to be hashed.

The size of the resulting digest in bytes. This is always 20.

A sha object has all the methods the md5 objects have, plus one:

hexdigest ()
Return the digest value as a string of hexadecimal digits. This may be used to exchange the value safely in email or other non-binary environments.

See Also:

The Secure Hash Algorithm is defined by NIST document FIPS PUB 180-1: Secure Hash Standard, published in April of 1995. It is available online as plain text at http://csrc.nist.gov/fips/fip180-1.txt (at least one diagram was omitted) and as PostScript at http://csrc.nist.gov/fips/fip180-1.ps.

Send comments on this document to python-docs@python.org.