Table of Contents

Class: sha256 src/sha256.py

256 bit Secure Hash Algorithm (SHA-256)

The sha256 python class builds on NIST's SHA 256 implementation written in ANSI C by Aaron D. Gifford. The interface is very much like the standard python sha, the primary difference being the length of the digest. This class extends sha from 160 to 256 bits.

Usage Example:

    >>> from sha256.sha256 import sha256

    >>> hasher = sha256()

    >>> hasher.update('1234567890')

    >>> hasher.digest()

    'w߉q1?-Mp@
س'

    >>> hasher.update('1234567890')

    >>> hasher.digest()

    'P~x32cj +&πAk:/q'

The digest returned will invariably be 32 bytes (256 bits).

Methods   
__init__
digest
update
  __init__ 
__init__ ( self,  bytes=None )

Digest Context Initialisation. A new digesting context is created. Optionally, a string can be hashed immediately.

  digest 
digest ( self,  clear=0 )

Execute an SHA256 hash on the data stored in the context buffer. Return the digest in a python string with NULL bytes. Set clear to 1 if you wish to reset the digest context.

  update 
update ( self,  bytes )

Update the contents of the digest buffer by appending bytes to it. Accepts python strings with or without NULL bytes.

Exceptions   
TypeError( "Please supply a string." )

Table of Contents

This document was automatically generated on Thu Nov 29 11:11:22 2001 by HappyDoc version r1_6_1