Skip to content

Instantly share code, notes, and snippets.

@roffe
Created January 13, 2019 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roffe/c78ca609135779c3354a2f280315ba83 to your computer and use it in GitHub Desktop.
Save roffe/c78ca609135779c3354a2f280315ba83 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"fmt"
)
func main() {
signKey := "averylongandsecurekeywithmin32chars"
urlPath := "/resize"
url := "https%3A%2F%2Fwww.google.com%2Flogos%2Fdoodles%2F2015%2Fgoogles-new-logo-5078286822539264.3-hp2x.gif"
urlQuery := "nocrop=true&type=jpeg&url=" + url + "&width=200"
h := hmac.New(sha256.New, []byte(signKey))
h.Write([]byte(urlPath))
h.Write([]byte(urlQuery))
buf := h.Sum(nil)
fmt.Println(urlPath + "?" + urlQuery + "&sign=" + base64.RawURLEncoding.EncodeToString(buf))
}
/*
➜ go run sign.go
/resize?nocrop=true&type=jpeg&url=https%3A%2F%2Fwww.google.com%2Flogos%2Fdoodles%2F2015%2Fgoogles-new-logo-5078286822539264.3-hp2x.gif&width=200&sign=9Rawdy5gEmqGTRgxUOO7fFMYegivSQd1jNSuJljY2PM
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment