-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest4.go
More file actions
31 lines (28 loc) · 823 Bytes
/
test4.go
File metadata and controls
31 lines (28 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main
import (
"fmt"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"time"
)
func generateAuth(accessID, accessKey, action string) (string, error) {
date := time.Now().Format("Mon, 02 Jan 2006 15:04:05 GMT")
toSign := "GET\n"
toSign += "\n"
toSign += "application/json\n"
toSign += date + "\n"
toSign += "/" + action
hash := hmac.New(sha1.New, []byte(accessKey))
hash.Write([]byte(toSign))
signed := base64.StdEncoding.EncodeToString(hash.Sum(nil))
auth := "Authorization: LWS " + accessID + ":" + signed
return auth, nil
}
func main() {
accessID := "CWXYQX8Z1LDPZ5DJ14NG"
accessKey := "k/MOjnPk2yrjNecndc212kNocLX1yPVaq4PTNg=="
auth, err := generateAuth(accessID, accessKey, "PutMetricData")
fmt.Println(err)
fmt.Println(auth)
}