The hexdigest provided in the Python Hashlib library returns a string of length 32.
Md5sum is 128bit, which is 16 bytes, how do I convert a python string to 16 bytes?
Take a look at the following code
import hashlibdef get_md5(s): m = hashlib.md5(s) return m.hexdigest()def convert_md5(origin): result = [] s = "" for i in range(len(origin)): s += origin[i] if i %2 != 0 : int_hex = int(s, 16) result.append(int_hex) s = "" return resultif __name__=="__main__": sum = get_md5("hello world") print sum print len(sum) cv_sum = convert_md5(sum) print cv_sum print len(cv_sum)
Output
5eb63bbbe01eeed093cb22bb8f5acdc3
32
[94, 182, 59, 187, 224, 30, 238, 208, 147, 203, 34, 187, 143, 90, 205, 195]
16
The converted output list is the value represented by each byte of the 10 binary output, for example, the last byte, 0xc3 = = 195
Python how to convert MD5 to 16 bytes