Explorar o código

:add 增加HmacSHA1 的加密方法

fly hai 1 ano
pai
achega
f5b4069e9f
Modificáronse 1 ficheiros con 7 adicións e 0 borrados
  1. 7 0
      algorithm/hash/sha.go

+ 7 - 0
algorithm/hash/sha.go

@@ -9,6 +9,13 @@ import (
 	"io"
 )
 
+func ComputeHmacSHA1(data string, secret string) string {
+	key := []byte(secret)
+	h := hmac.New(sha1.New, key)
+	h.Write([]byte(data))
+	return fmt.Sprintf("%x", h.Sum(nil))
+}
+
 func ComputeSHA1(data string) string {
 	t := sha1.New()
 	_, _ = io.WriteString(t, data)