I know there is hashlib in Python, but I want to achieve the same result as in Go below:
package main
import (
"crypto/md5"
"fmt"
)
func main() {
data := []byte("12345")
fmt.Println("sum ", md5.Sum(data))
}
As func md5.Sum described, it calculates "MD5 checksum of the data". However, I don't find any similar function in Python.
Is there any way to achieve md5.Sum
in Python as in Go?
The output of program above is a slice other than a string:
sum [32 44 185 98 172 89 7 91 150 75 7 21 45 35 75 112]
Based on PM 2Ring's solution, here is a working program,
from hashlib import md5
hexv = md5(b'12345').hexdigest()
l = [str(int(i+j,16)) for i, j in zip(hexv[::2], hexv[1::2])]
print("sum [" + ", ".join(l)+"]")
This prints,
sum [130, 124, 203, 14, 234, 138, 112, 108, 76, 52, 161, 104, 145, 248, 78, 123]