Skip to content

Instantly share code, notes, and snippets.

@edwinlab
Last active February 10, 2019 04:27
Show Gist options
  • Save edwinlab/038be7afe55b50c0156a73a42e9b4007 to your computer and use it in GitHub Desktop.
Save edwinlab/038be7afe55b50c0156a73a42e9b4007 to your computer and use it in GitHub Desktop.
Generate Microsoft Azure Storage account shared access signature with Golang
package main
import (
"crypto/hmac"
"crypto/sha256"
"fmt"
"encoding/base64"
"strings"
)
const (
AZURE_ACCOUNT_NAME = "",
AZURE_ACCESS_KEY = "",
AZURE_CONTAINER_NAME = "",
)
func main() {
blob := fmt.Sprintf("/%s/%s/%s", AZURE_ACCOUNT_NAME, AZURE_CONTAINER_NAME, "filename.jpg")
sA := []string{"r", // permissions
"",
"2019-02-10T00:00:00Z", // expiry time
blob,
"",
"2019-02-09", // API version
"", "", "", "", ""}
toSign := strings.Join(sA, "\n")
decodingAccessKey, _ := base64.StdEncoding.DecodeString(AZURE_ACCESS_KEY)
h := hmac.New(sha256.New, []byte(decodingAccessKey))
h.Write([]byte(toSign))
signature := base64.StdEncoding.EncodeToString(h.Sum(nil))
fmt.Println("s: " + signature)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment