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

在Python中使用hashlib检测可用的非标准哈希算法,python,hash,python-2.7,checksum,ripemd,Python,Hash,Python 2.7,Checksum,Ripemd,根据Python文档,hashlib模块(MD5和SHA***)只保证支持少数散列算法。我如何检测是否有其他算法可用?(比如RIPEMD-160)当然,我可以尝试使用文档中的RIPEMD-160示例来使用它,但我不确定它会如何抱怨。它会抛出异常吗?如果是,是哪个异常?在shell中尝试一下: >>> h = hashlib.new('ripemd161')

根据Python文档,hashlib模块(MD5和SHA***)只保证支持少数散列算法。我如何检测是否有其他算法可用?(比如RIPEMD-160)当然,我可以尝试使用文档中的RIPEMD-160示例来使用它,但我不确定它会如何抱怨。它会抛出异常吗?如果是,是哪个异常?

在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
h=hashlib.new('ripemd161') 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 文件“/usr/lib/python2.7/hashlib.py”,第124行,在新的 return\u get\u内置构造函数(名称)(字符串) 文件“/usr/lib/python2.7/hashlib.py”,第91行,在内置构造函数中 raise VALUERROR('不支持的哈希类型%s'%name)) ValueError:不支持的哈希类型ripemd161
在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
h=hashlib.new('ripemd161') 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 文件“/usr/lib/python2.7/hashlib.py”,第124行,在新的 return\u get\u内置构造函数(名称)(字符串) 文件“/usr/lib/python2.7/hashlib.py”,第91行,在内置构造函数中 raise VALUERROR('不支持的哈希类型%s'%name)) ValueError:不支持的哈希类型ripemd161
谢谢,这正是我想要的。我的问题是RIPEMD-160在我的系统上可用,所以我不知道它会抛出哪个异常。现在我知道了,谢谢!计时器启动时将标记为答案。谢谢,这正是我想要的。我的问题是RIPEMD-160在我的系统上可用,所以我不知道它会抛出哪个异常。现在我知道了,谢谢!定时器启动时,将标记为应答。