Procházet zdrojové kódy

:add 增加HmacSHA1 的加密方法

fly před 1 rokem
rodič
revize
f5b4069e9f
1 změnil soubory, kde provedl 7 přidání a 0 odebrání
  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)