You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jcook-sdk/util/security/md5.go

32 lines
483 B

3 years ago
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)))
}