Skip to content

Instantly share code, notes, and snippets.

@WGrape
Last active May 8, 2022 17:23
Show Gist options
  • Save WGrape/625e69712cc128e4d729d8f0812012d4 to your computer and use it in GitHub Desktop.
Save WGrape/625e69712cc128e4d729d8f0812012d4 to your computer and use it in GitHub Desktop.
How to use md5 in golang ?
import (
"crypto/md5"
"encoding/hex"
)
// Md5 encode the str
func Md5(s string) string {
h := md5.New()
n, err := h.Write([]byte(s))
if err != nil || n == 0 {
return ""
}
return hex.EncodeToString(h.Sum(nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment