Skip to content

Commit 0b90cf7

Browse files
committed
more hash func
1 parent d375fec commit 0b90cf7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

hash.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package bot
2+
3+
import (
4+
"crypto/hmac"
5+
"crypto/sha1"
6+
"crypto/sha256"
7+
"encoding/hex"
8+
)
9+
10+
func HmacSha256(key, data []byte) string {
11+
hash := hmac.New(sha256.New, key)
12+
hash.Write(data)
13+
return hex.EncodeToString(hash.Sum(nil))
14+
}
15+
16+
func HmacSha1(hmacKey string, data []byte) string {
17+
hash := hmac.New(sha1.New, []byte(hmacKey))
18+
hash.Write(data)
19+
return hex.EncodeToString(hash.Sum(nil))
20+
}

0 commit comments

Comments
 (0)