[Python] Each hash

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

[Python] Each hash
[Python] Dictionary (hash)
Python
Hash method (open address method) in Python
Manage each Python version with Homebrew
kafka python
Python basics ⑤
python + lottery 6
Python Summary
Built-in python
Python comprehension
Python technique
Studying python
Python 2.7 Countdown
Python memorandum
Python FlowFishMaster
Python service
python tips
python function ①
Python basics
Slowly hash passwords using bcrypt in Python
Python memo
ufo-> python (3)
Python comprehension
install python
Python Singleton
Python basics ④
Python Memorandum 2
python memo
Python Jinja2
Python increment
atCoder 173 Python
[Python] function
Python installation
python tips
Try python
Python memo
Python iterative
Python2 + word2vec
Python functions
Python tutorial
python underscore
Python summary
Start python
[Python] Sort
Note: Python
Python basics ③
python log
Python basics
[Scraping] Python scraping
Python update (2.6-> 2.7)
Hash in Perl is a dictionary in Python
python memo
Python memorandum
Python # sort
ufo-> python
Python nslookup
python learning
[Rpmbuild] Python 3.7.3.
hashlib hash
Prorate Python (1)