package security import ( "crypto/md5" "encoding/hex" "fmt" "sort" "strings" ) func Md5OrderlyWithSecret(secret string, data map[string]string) string { h := md5.New() var order []string for key, _ := range data{ order = append(order, key) } sort.Strings(order) h.Write([]byte(secret)) for _, value := range order{ h.Write([]byte(fmt.Sprintf("%s%s", value, data[value]))) } h.Write([]byte(secret)) return strings.ToUpper(hex.EncodeToString(h.Sum(nil))) }