Created
January 13, 2019 20:56
-
-
Save roffe/c78ca609135779c3354a2f280315ba83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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