package security import ( "crypto/hmac" "crypto/sha1" "encoding/base64" "fmt" "sort" "strings" ) func map2str(data map[string]string, sep string) string { var temp []string for key, _ := range data { temp = append(temp, key) } sort.Strings(temp) var tt []string for _, v := range temp { tt = append(tt, fmt.Sprintf("%s=%s", v, data[v])) } return strings.Join(tt, sep) } func Sha1OrderlyWithBase64(secret string, data map[string]string) string { h := hmac.New(sha1.New, []byte(secret)) str := map2str(data, "&") h.Write([]byte(str)) return base64.StdEncoding.EncodeToString(h.Sum(nil)) }