Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hashlib can't find ripemd160

When I try to use ripemd160 with hashlib it says it can't find it.

I used easy_install hashlib which installed hashlib but it still can't find ripemd160.

I'm using Ubuntu and python2.7

def hexHash(str, withHash = None):
    h = hashlib.new('ripemd160')
    h.update(str)
    if withHash != None:
        return h.hexdigest()[0:6]
    else:
        return '#'+h.hexdigest()[0:6]

ValueError: unsupported hash type

like image 349
wizardzeb Avatar asked Dec 20 '25 22:12

wizardzeb


1 Answers

Hashlib is part of Python's standard library, so you don't have to install it.

However, the only hash algorithms that are guaranteed to be available are md5, sha1, sha224, sha256, sha384, and sha512.

Others may be available depending on the SSL library that is used on your platform.

You can run openssl list-message-digest-algorithms in a terminal to see which algorithms are available.

(Note: as of openssl 1.1.1, the above command doesn't work. Try openssl dgst -list)

The above assumes that Python uses the system's SSL library, which might not be the case.

Or (better) from Python:

import hashlib

print(hashlib.algorithms_available)

If ripemd160 isn't available, you should probably look into re-installing your SSL library with different options. (Assuming Python uses the system's SSL)

If you are changing your SSL library to one with a different version number, you will have to rebuild anything that depends on it as well.

like image 158
Roland Smith Avatar answered Dec 22 '25 12:12

Roland Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!