When using hashes etc. for security, even if it is displayed as it is with print, it will be garbled and can not be read, so a memo when I was playing around with it.
'test' == b'test'
Since it is an srt type and a bytes type, of course it is different, so False is returned.
'test'.encode('utf-8') == b'test'
True is returned because str is converted to bytes type.
from binascii import hexlify
hexlify(b'A')
"B'41'" is returned.
from binascii import unhexlify
unhexlify(b'41')
Since it is the opposite of hexlify, "b'A'" is returned.
b'A'.decode('utf-8')
import hashlib
from binascii import hexlify
origin = 'Ah'
encoded_origin = origin.encode('utf-8')
hash_obj = hashlib.sha256()
hash_obj.update(encoded_origin)
digest = hash_obj.digest()
print(digest) #Humans can't read
print(hexlify(digest)) #Human readable
Recommended Posts