【问题标题】:Detection of available non-standard hash algorithms using hashlib in Python在 Python 中使用 hashlib 检测可用的非标准哈希算法
【发布时间】:2012-03-14 15:56:29
【问题描述】:

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

【问题讨论】:

    标签: python hash python-2.7 checksum ripemd


    【解决方案1】:

    只需在 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
    

    【讨论】:

    • 谢谢,这正是我想要的。我的问题是 RIPEMD-160 is 在我的系统上可用,所以我不知道它会抛出哪个异常。现在我知道了,谢谢!计时器到时将标记为答案。
    猜你喜欢
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 2021-11-19
    • 1970-01-01
    • 2013-11-10
    相关资源
    最近更新 更多