python 尝试运行加密代码时,出现错误:“模块'hashlib'没有属性'scrypt'"

fjnneemd  于 2022-12-02  发布在  Python
关注(0)|答案(2)|浏览(527)

正如我在标题中提到的,我试图通过使用以下简单的代码来运行库密码:

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。

zwghvu4y

zwghvu4y1#

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

8i9zcol2

8i9zcol22#

    • 检查以下几点:**

检查已安装的所有版本
该Python

//use python or python3 as per your needs

检查所有版本的安装位置
其中Python

//use python or python3 as per your needs

在我的例子中,我有两条路,如下所示:

/usr/bin/python 
/usr/local/bin/python

因此,现在检查VS代码,

  • Command + Shit + P组合键
  • 搜索/选择Python解释器
  • 选择您正在使用的相应版本(如果未列出)添加相应的路径并选择相同的路径。

这个解决方案对我很有效:)

相关问题