Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SHA256 hash in Python 2.4

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.

like image 428
hyperboreean Avatar asked Aug 25 '09 13:08

hyperboreean


People also ask

Is SHA256 32 bytes?

What we see is a string representation of 32 bytes which results in 64 bytes of individual chars. However a group of two chars is actually one byte, ranging from 0 up to 255 in decimal.

Is SHA256 Crackable?

The SHA-256 algorithm is not yet easily cracked. Moreover SHA256 algorithm, such as SHA-512 algorithms compared to other secure top model is calculated more quickly is currently one of the most widely used algorithms. However, IT experts talk about allegations and developments that SHA-256 may be vulnerable very soon.


3 Answers

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 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.

like image 79
af. Avatar answered Oct 13 '22 23:10

af.


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
like image 41
tonfa Avatar answered Oct 13 '22 22:10

tonfa


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

like image 4
Laurence Rowe Avatar answered Oct 13 '22 22:10

Laurence Rowe