1 Star 0 Fork 0

litian/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sign2.go 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
package awsauth
import (
"encoding/base64"
"net/http"
"net/url"
"strings"
)
func prepareRequestV2(req *http.Request, keys Credentials) *http.Request {
keyID := keys.AccessKeyID
values := url.Values{}
values.Set("AWSAccessKeyId", keyID)
values.Set("SignatureVersion", "2")
values.Set("SignatureMethod", "HmacSHA256")
values.Set("Timestamp", timestampV2())
augmentRequestQuery(req, values)
if req.URL.Path == "" {
req.URL.Path += "/"
}
return req
}
func stringToSignV2(req *http.Request) string {
str := req.Method + "\n"
str += strings.ToLower(req.URL.Host) + "\n"
str += req.URL.Path + "\n"
str += canonicalQueryStringV2(req)
return str
}
func signatureV2(strToSign string, keys Credentials) string {
hashed := hmacSHA256([]byte(keys.SecretAccessKey), strToSign)
return base64.StdEncoding.EncodeToString(hashed)
}
func canonicalQueryStringV2(req *http.Request) string {
return req.URL.RawQuery
}
func timestampV2() string {
return now().Format(timeFormatV2)
}
const timeFormatV2 = "2006-01-02T15:04:05"
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/litian33/machine.git
git@gitee.com:litian33/machine.git
litian33
machine
machine
v0.3.0

搜索帮助