gpt4 book ai didi

Python:无法从 hashlib 导入 scrypt

转载 作者:太空宇宙 更新时间:2023-11-04 00:02:07 26 4
gpt4 key购买 nike

我需要使用 scrypt 算法,因为我已经在使用 hashlib,所以我想……为什么不呢?我已经查过了 this它指出 OpenSSL 1.1+ 是必要的。此外,根据 official doc :

hashlib.scrypt(password, *, salt, n, r, p, maxmem=0, dklen=64)

...

Availability: OpenSSL 1.1+.

New in version 3.6.

我确保拥有最新版本的 openssl:

# openssl version
OpenSSL 1.1.1b 26 Feb 2019

我还尝试运行 python3.6 和 python3 (3.4),但都说它们无法导入 scrypt:

# python3.6
Python 3.6.5 (default, Apr 10 2018, 17:08:37)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from hashlib import pbkdf2_hmac
>>> from hashlib import scrypt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'scrypt'

如您所见,pbkdf2_hmac 等其他方法也有效。有什么问题吗?

此外,hashlib.scrypt(password, *, salt, n, r, p, maxmem=0, dklen=64) 中的* 是什么?

最佳答案

我的 mac 正在运行 OpenSSL 1.1.1 2018 年 9 月 11 日。我用 python3.6 重现了你的导入症状,并发现 scrypt 导入 python3.7 就好了。您可以考虑尝试 3.7。

签名中的*是比较新的语法这标志着位置参数的结束。所以你不能调用 scrypt('secret', 'mySalt')。您需要指定关键字参数,例如scrypt(' secret ', salt='mySalt').目的是通过使用错误的 arg 顺序更难调用错误。这对于加密 API 尤其重要,其中许多参数不透明且难以验证。

关于Python:无法从 hashlib 导入 scrypt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55366629/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com