Here's an example of how to generate an MD5 hash from a string in Go:
main.go416 chars25 lines
In this code, we first create a new md5
hash using md5.New()
. We then write our string to the hash using hash.Write([]byte(str))
. Finally, we get the resulting hash value as a byte slice using hash.Sum(nil)
and convert it to a string using fmt.Sprintf("%x", hashBytes)
. The resulting hash string is then printed to the console.
gistlibby LogSnag