python - 无法导入 "hashlib"

标签 python encryption hash sha1 hashlib

我试图用 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/

相关文章:

c++ - 使用带有安全字符串的openssl加密文件

ruby-on-rails - 有谁知道 "expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS"是什么意思?

python - 回文,没有字符串不能返回 False

python - 无法在 Python Virtualbox API 中恢复 VM

python - 性能: Class Based Views VS Function Based Views

ruby - 使用正则表达式找不到哈希键值

ruby - 有没有办法避免写==,eql?和 Ruby 中的哈希方法(模板类?)

python scipy ode dopri5 'larger nmax needed'

python - 在 Python 中使用 Fernet 进行对称加密 - 主密码用例

javascript - JS中RSA加解密成功,C#中解密失败