How Do You Reencode A Python String Via Packing And Unpacking Using Binascii?
I have a file hashed to a standard md5 Hash Correction: OpenSSL Hashes are HEXDECIMAL representations. MD5 Hash: 57ED2E029BF9CA39383D2A671EF4FB50 I have a program that requires
Solution 1:
Here's how you can do the conversion with binascii
. It requires two conversions, one from hex to binary and another from binary to base64.
>>>hex_hash = '4bd2f7940a1ec86efe1d1178b4cb23b7'>>>binascii.b2a_base64(binascii.a2b_hex(hex_hash))
'S9L3lAoeyG7+HRF4tMsjtw==\n'
Solution 2:
The most important thing to realize was that the openssl md5 hash is calculated the same way as the hashlib.md5(..).hexdigest() method
import base64
import hashlib
hex_hash = hashlib.md5(open("putty_upx.exe").read()).hexdigest()
>>'4bd2f7940a1ec86efe1d1178b4cb23b7'
hex_hash.decode("hex")
>>'K\xd2\xf7\x94\n\x1e\xc8n\xfe\x1d\x11x\xb4\xcb#\xb7'
b64_md5_hash = base64.b64encode(hex_hash.decode("hex"))
>>'S9L3lAoeyG7+HRF4tMsjtw=='
len(b64_md5_hash)
>>24
Post a Comment for "How Do You Reencode A Python String Via Packing And Unpacking Using Binascii?"