Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string with HEX MD5 to base64 encoding

I need to convert a HEX-type md5 string to the base64 version in Python.

For example, if I had MD5: 4297f44b13955235245b2497399d7a93

I need the code to produce Qpf0SxOVUjUkWySXOZ16kw==

This is identical to another SO asking for a C# implementation, but I need the Python code. This is similar to this SO asking to convert a single binary number to base64 in Python.

like image 242
saladi Avatar asked Jul 14 '26 08:07

saladi


1 Answers

Depending on the version of Python you are running, the following will work:

Python 2

base64.b64encode("4297f44b13955235245b2497399d7a93".decode("‌​hex"))

Python 3

base64.b64encode(bytes.fromhex("4297f44b13955235245b2497399d‌​7a93"))
like image 83
Phylogenesis Avatar answered Jul 20 '26 10:07

Phylogenesis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!