我试图用 sha1 加密一个字符串,但我从服务器收到一个错误:
"No Module Named hashlib"
通过使用以下代码:
import hashlib
encrypted = hashlib.sha1(string)
encrypted = encrypted.digest()
我将不胜感激,
谢谢, 盖多尔
最佳答案
您的 Python 版本可能 < 2.5。使用 sha
模块代替。
区别如下:
>>> import sha
>>> s = sha.new()
>>> s.update('hello')
>>> s.digest()
'\xaa\xf4\xc6\x1d\xdc\xc5\xe8\xa2\xda\xbe\xde\x0f;H,\xd9\xae\xa9CM'
对比
>>> import hashlib
>>> hashlib.sha1('hello').digest()
'\xaa\xf4\xc6\x1d\xdc\xc5\xe8\xa2\xda\xbe\xde\x0f;H,\xd9\xae\xa9CM'
关于python - 无法导入 "hashlib",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6557760/