Modify: use base64-URLEncoding to encode signature hash

This commit is contained in:
HFO4 2020-01-17 14:39:30 +08:00
parent 68d4a86166
commit 21ec3fc710

View file

@ -3,7 +3,7 @@ package auth
import ( import (
"crypto/hmac" "crypto/hmac"
"crypto/sha256" "crypto/sha256"
"fmt" "encoding/base64"
"io" "io"
"strconv" "strconv"
"strings" "strings"
@ -25,7 +25,7 @@ func (auth HMACAuth) Sign(body string, expires int64) string {
return "" return ""
} }
return fmt.Sprintf("%x", h.Sum(nil)) + ":" + expireTimeStamp return base64.URLEncoding.EncodeToString(h.Sum(nil)) + ":" + expireTimeStamp
} }
// Check 对给定Body和Sign进行鉴权包括对expires的检查 // Check 对给定Body和Sign进行鉴权包括对expires的检查