views:

817

answers:

3

Hi, Is there a way I can calculate a SHA256 hash in Python 2.4 ? (I emphasize: Python 2.4) I know how to do it in Python 2.5 but unfortunately it's not available on my server and an upgrade will not be made. I have the same problem as the guy in this question, but using Python 2.4. Any help will be greatly appreciated.

EDIT: Sorry, I mean SHA 256. I was too in a hurry. Sorry again.

+8  A: 

Yes you can. With Python 2.4, there was SHA-1 module which does exactly this. See the documentation.

However, bear in mind that code importing from this module will cause DeprecationWarnings when run with newer Python.

Ok, as the requirement was tightened to be SHA-256, using the SHA-1 module in standard library isn't a enough. I'd suggest checking out pycrypto, it has a SHA-256 implementation. There are also windows binary releases to match older Pythons, follow the links from Andrew Kuchlings old PyCrypto page.

af
+2  A: 

You can use the sha module, if you want to stay compatible, you can import it like this:

try:
    from hashlib import sha1
except ImportError:
    from sha import sha as sha1
tonfa
+1  A: 

There is a backported version of hashlib at http://pypi.python.org/pypi/hashlib and I just backported the newer hmac version and put it up at http://pypi.python.org/pypi/hmac

Laurence Rowe