Python:无法从hashlib导入scrypt
我需要使用scrypt算法,因为我已经在使用hashlib了,我想。。。为什么不呢?我已经检查过了,它指出OpenSSL 1.1+是必要的。此外,根据: scrypt(密码,*,salt,n,r,p,maxmem=0,dklen=64) 可用性:OpenSSL 1.1+ 3.6版中的新版本 我确保有最新版本的openssl:Python:无法从hashlib导入scrypt,python,python-3.x,openssl,hashlib,scrypt,Python,Python 3.x,Openssl,Hashlib,Scrypt,我需要使用scrypt算法,因为我已经在使用hashlib了,我想。。。为什么不呢?我已经检查过了,它指出OpenSSL 1.1+是必要的。此外,根据: scrypt(密码,*,salt,n,r,p,maxmem=0,dklen=64) 可用性:OpenSSL 1.1+ 3.6版中的新版本 我确保有最新版本的openssl: # openssl version OpenSSL 1.1.1b 26 Feb 2019 我还尝试运行python3.6和python3(3.4),它们都表示无法导入
# 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'
#python3.6
Python 3.6.5(默认值,2018年4月10日,17:08:37)
linux上的[GCC 4.8.5 20150623(Red Hat 4.8.5-16)]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>从hashlib导入pbkdf2_hmac
>>>从hashlib导入scrypt
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:无法导入名称“scrypt”
如您所见,其他方法如pbkdf2_hmac
也可以工作。有什么不对劲吗
另外,hashlib.scrypt(密码,*,salt,n,r,p,maxmem=0,dklen=64)中的
*
是什么?我的mac在2018年9月11日运行OpenSSL 1.1.1
。
我用python3.6复制了你的进口症状,
并发现,scrypt
与python3.7一起导入就可以了。
你可以考虑尝试3.7。
签名中的*
是一种相对较新的语法
它标志着位置参数的结束。
因此,您不能作为scrypt('secret','mySalt')
调用。
您需要指定关键字args,例如scrypt('secret',salt='mySalt')
。
这样做的目的是通过使用错误的arg顺序使错误调用变得更加困难。
这对于加密API尤其重要,
其中许多参数不透明且难以验证。您是对的。我花了很多时间从源代码Python3.7进行编译,但它很有效。我希望医生们能更清楚一点。感谢您解释位置args语法。我没有意识到这一点。