【问题标题】:While trying to run cryptocode I get the error: "module 'hashlib' has no attribute 'scrypt'"尝试运行加密代码时出现错误:“模块'hashlib'没有属性'scrypt'”
【发布时间】:2021-09-16 08:02:33
【问题描述】:

正如我在标题中提到的,我正在尝试使用这个简单的代码来运行库密码:

import cryptocode

password = "This is a test"
key = "My Key"


def encrypt(password, key):
    return cryptocode.encrypt(password, key)


def decrypt(encryptetpass):
    return cryptocode.decrypt(encryptetpass, key)


encrypted_pass = encrypt(password, key)
print(encrypted_pass)

print(decrypt(encrypted_pass))

在 Windows 上本地运行时,我没有收到任何错误,但在 Linux 上尝试相同的操作会产生标题中提到的错误:

(venv) pwd$ python3.9 crypt_test.py

Traceback (most recent call last):
  File "/crypt_test.py", line 15, in <module>
    encrypted_pass = encrypt(password, key)
  File "/crypt_test.py", line 8, in encrypt
    return cryptocode.encrypt(password, key)
  File "/venv/lib/python3.9/site-packages/cryptocode/myfunctions.py", line 16, in encrypt
    private_key = hashlib.scrypt(
AttributeError: module 'hashlib' has no attribute 'scrypt'

我尝试更新 Openssl,重新安装了我的 venv 和 Python。

【问题讨论】:

  • 请发布您与minimal reproducible example 相处的产生错误的完整回溯
  • 另外,你用的是什么版本的python?是否有可能在 Linux 上使用 3.6 甚至 python2 之前的 python 版本?
  • @buran,我做了编辑。如您所见,我使用的是 Python3.9。
  • hashlib.scrypt 注意到它需要 OpenSSL 1.1+,听起来你的 Python 的 Linux 版本是使用其他版本的 OpenSSL 构建的

标签: python cryptography hashlib


【解决方案1】:

您是否尝试构建最新的 OpenSSL?我在这里看到说明:https://www.howtoforge.com/tutorial/how-to-install-openssl-from-source-on-linux/ (无法尝试这个,因为我没有运行 Linux)。请让我们知道这是否有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 2018-12-18
    • 2017-08-11
    • 1970-01-01
    相关资源
    最近更新 更多