运行 MacOS 10.14.6。刚刚运行 MacPorts 更新。采用 Python 3.9.7 -> 3.9.8 和 OpenSSL 1.1.3 -> 3。
运行现有的 Python 代码会发现 hashlib
出现问题,并且 RIPEMD160 不再可用(Whirlpool 和可能的其他摘要也不可用)。
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/hashlib.py", line 160, in __hash_new
return _hashlib.new(name, data, **kwargs)
ValueError: [digital envelope routines] initialization error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "testhash.py", line 3, in <module>
r160 = hashlib.new('ripemd160')
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/hashlib.py", line 166, in __hash_new
return __get_builtin_constructor(name)(data)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/hashlib.py", line 123, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type ripemd160
可以简单地复制
import hashlib
r160 = hashlib.new('ripemd160')
方法 hashlib.algorithms_available
表明 hashlib
认为 ripemd160
是可用的:
Available: {'sha512', 'shake_128', 'ripemd160', 'sha224', 'md5', 'whirlpool', 'blake2b', 'sha3_512', 'md4', 'sha3_256', 'sha256', 'shake_256', 'md5-sha1', 'sha1', 'sha512_224', 'sm3', 'mdc2', 'blake2s', 'sha3_384', 'sha3_224', 'sha512_256', 'sha384'}
Guaranteed: {'sha3_512', 'sha512', 'sha1', 'shake_128', 'sha3_384', 'sha224', 'md5', 'sha256', 'sha3_224', 'sha3_256', 'shake_256', 'blake2b', 'blake2s', 'sha384'}
并询问 openssl
以确认它确实具有该功能。
回滚,同样的问题。我宁愿保持最新的安装。 RIPEMD160 的使用是没有商量余地的。
我怀疑给 ports
正确的开关、命令、环境变量会说服重新编译工作,但我不知道是什么。
关于发生了什么以及如何解决的任何想法?
最佳答案
所有旧的加密功能仍然存在于 OpenSSL3 中,但现在需要手动启用。参见 issue 16994 of OpenSSL github project了解详情。
要快速启用它,请运行以下命令找到包含 OpenSSL 配置文件或符号链接(symbolic link)的目录:
openssl version -d
您现在可以转到目录并编辑配置文件(可能需要使用 sudo):
nano openssl.cnf
确保配置文件包含以下行:
openssl_conf = openssl_init
[openssl_init]
providers = provider_sect
[provider_sect]
default = default_sect
legacy = legacy_sect
[default_sect]
activate = 1
[legacy_sect]
activate = 1
测试平台:OpenSSL 3.0.2、Python 3.10.4、Linux Ubuntu 22.04 LTS aarch64,目前无法访问其他平台。
关于python-3.x - Python 3.9.8、hashlib 和 RIPEMD160,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69922525/