简体   繁体   English

在Python中使用hashlib检测可用的非标准哈希算法

[英]Detection of available non-standard hash algorithms using hashlib in Python

According to the Python documentation, only a few hash algorithms are guaranteed to be supported by the hashlib module (MD5 and SHA***). 根据Python文档,hashlib模块(MD5和SHA ***)只支持一些哈希算法。 How would I go about detecting if other algorithms are available? 如何检测其他算法是否可用? (like RIPEMD-160) Of course, I could try to use it using the RIPEMD-160 example from the documentation, but I'm not sure how it would complain. (比如RIPEMD-160)当然,我可以尝试使用文档中的RIPEMD-160示例来使用它,但我不确定它会如何抱怨。 Would it throw an exception, if yes, which exception? 它是否会抛出异常,如果是,哪个异常?

Just try it in a shell: 只需在shell中尝试:

>>> h = hashlib.new('ripemd161')                                                                                                                     
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/hashlib.py", line 124, in __hash_new
    return __get_builtin_constructor(name)(string)
  File "/usr/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type ripemd161

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM