Browse Source

update hmac sha1

ls 1 year ago
parent
commit
fa526bda21
1 changed files with 11 additions and 0 deletions
  1. 11 0
      hash.go

+ 11 - 0
hash.go

@@ -20,6 +20,7 @@ func SHA512(data []byte) ([]byte, error) {
 	return hash.Sum(nil), nil
 }
 
+// HmacSHA256 hmac with sha256
 func HmacSHA256(k, s []byte) ([]byte, error) {
 	hash := hmac.New(sha256.New, k)
 	_, err := hash.Write(s)
@@ -49,3 +50,13 @@ func SHA1(data string) string {
 	hash.Write([]byte(data))
 	return hex.EncodeToString(hash.Sum(nil))
 }
+
+// HmacSHA1 hmac with sha1
+func HmacSHA1(k, s []byte) ([]byte, error) {
+	hash := hmac.New(sha1.New, k)
+	_, err := hash.Write(s)
+	if err != nil {
+		return nil, err
+	}
+	return hash.Sum(nil), nil
+}