问题
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?
回答1:
You could try using the standalone hashlib library.
回答2:
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.
来源:https://stackoverflow.com/questions/9348655/pycrypto-and-python-2-4-3-issue