I have a string that contain a SHA256 digest in hexadecimal like blow:
"257612236efae809c23330ab67cf61f73aec938503f3ce126c34c6a32059f5f0"
and I want to convert it to hash.digest()
that can be like below:
b'%v\x12#n\xfa\xe8\t\xc230\xabg\xcfa\xf7:\xec\x93\x85\x03\xf3\xce\x12l4\xc6\xa3 Y\xf5\xf0'
how can I achive this?
I use Crypto.Hash
and python 3.3.2
SHA256 Results The SHA256 online generator allows you to instantly generate a SHA256 (32-byte) hash of any string or input value, which is then returned as a hexadecimal number of 64 digits.
hex() function in Python. hex() function is one of the built-in functions in Python3, which is used to convert an integer number into it's corresponding hexadecimal form. Syntax : hex(x) Parameters : x - an integer number (int object) Returns : Returns hexadecimal string.
From the documentation for hash. hexdigest() : the digest is returned as a string object of double length, containing only hexadecimal digits. This may be used to exchange the value safely in email or other non-binary environments.
Use binascii.unhexlify
:
>>> import binascii
>>> binascii.unhexlify("257612236efae809c23330ab67cf61f73aec938503f3ce126c34c6a32059f5f0")
b'%v\x12#n\xfa\xe8\t\xc230\xabg\xcfa\xf7:\xec\x93\x85\x03\xf3\xce\x12l4\xc6\xa3 Y\xf5\xf0'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With