import hashlib
val = "[email protected]"
# Python2
# >>> [i for i in dir(hashlib) if i.find("sha") != -1]
# ['sha1', 'sha224', 'sha256', 'sha384', 'sha512']
md5val = hashlib.md5(val).hexdigest()
sha1val = hashlib.sha1(val).hexdigest()
# Python3
# >>> sha1val = hashlib.sha1(val).hexdigest()
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# TypeError: Unicode-objects must be encoded before hashing
val = val.encode("ascii")
sha1val = hashlib.sha1(val).hexdigest()
Recommended Posts