Aamir Rind
Aamir Rind

Reputation: 39659

pycrypto and python 2.4.3 issue

I am working on a project and the cPanel which is provided to me by employer is having python 2.4.3 (too old version). The problem is i need to use pycrypto. So i am importing SHA256. The problem is here SHA256.py:

try:
    import hashlib
    hashFactory = hashlib.sha256

except ImportError:
    from Crypto.Hash import _SHA256
    hashFactory = _SHA256 

hashlib is not available in python 2.4.3 so it went to import _SHA256 but there is no _SHA256 in Cryto.Hash folder. Is this is bug of pycrypto? or i can not use this module for python 2.4.3?? Any workaround for this problem?

Upvotes: 0

Views: 1779

Answers (2)

SquareRootOfTwentyThree
SquareRootOfTwentyThree

Reputation: 7776

Quite a few algorithms in PyCrypto are actually written in C, rather than in pure python. SHA256 is amongst them. In order to use it, you must either install a complete pycrypto binary package or follow the instructions in the PyCrypto's README file. In the latter case, you will need to install the development environment first.

Both options are platform and OS specific, but once done, it will be simply a matter of calling:

from Crypto.Hash import SHA256
hash = SHA256.new()
hash.update('message')

There is no need to try to import it from hashlib first.

Upvotes: 2

Gareth Latty
Gareth Latty

Reputation: 89007

You could try using the standalone hashlib library.

Upvotes: 0

Related Questions