As part of a work project I am porting a Perl library to Python. I'm comfortable with Python, much (much) less so with Perl.
The perl code uses Digest::MD5. This module has three functions:
md5($data)
takes in data and spits out md5 digest in binarymd5_hex($data)
takes in data and spits out md5 digest in hexmd5_base64($data)
takes in data and spits out md5 digest in base64 encoding
I can replicate md5_hex with something like this:
import hashlib
string = 'abcdefg'
print(hashlib.md5(string.encode()).hexdigest())
Which works fine (same inputs give same outputs at least). I can't seem to get anything to match for the other two functions.
It doesn't help that string encodings are really not something I've done much with. I've been interpreting the perl functions as saying they take an md5 digest and then re-encode in binary or base64, something like this:
import hashlib
import base64
string = 'abcdefg'
md5_string = hashlib.md5(string.encode()).hexdigest()
print(base64.b64encode(md5_string))
but maybe that's wrong? I'm sure there's something fundamental I'm just missing.
The Perl doc is here: https://metacpan.org/pod/Digest::MD5