Эх сурвалжийг харах

:add 增加HmacSHA1 的加密方法

fly 1 жил өмнө
parent
commit
f5b4069e9f
1 өөрчлөгдсөн 7 нэмэгдсэн , 0 устгасан
  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)