Created
December 17, 2020 07:27
-
-
Save adityathebe/6af426c7b8cd9cdb4486eb1c3a32f4fc to your computer and use it in GitHub Desktop.
Calculate HS256 with secret keys read from a file
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
// https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/. | |
package main | |
import ( | |
"crypto/hmac" | |
"crypto/sha256" | |
"encoding/base64" | |
"fmt" | |
"io/ioutil" | |
"log" | |
) | |
func main() { | |
src := []byte("YOUR-MESSAGE") | |
key, err := ioutil.ReadFile("path-to-secret-key") | |
if err != nil { | |
log.Fatal(err) | |
} | |
mac := hmac.New(sha256.New, key) | |
mac.Write(src) | |
encoded := base64.StdEncoding.EncodeToString(mac.Sum(nil)) | |
fmt.Print(encoded) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment