Skip to content

Instantly share code, notes, and snippets.

@hugows
Created November 23, 2019 10:50
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 hugows/7aa6d70451dd475daf3831cec98fa30f to your computer and use it in GitHub Desktop.
Save hugows/7aa6d70451dd475daf3831cec98fa30f to your computer and use it in GitHub Desktop.
Alternative to jwt-go
package main
import (
"fmt"
"golang.org/x/crypto/nacl/auth"
)
func main() {
plaintext := "Hello folks!"
key := "[1D|$kcW/X$bcH,Z]tkJ$^Z_>4bQ#wkA"
var secretKey [32]byte
copy(secretKey[:], key)
fmt.Printf("Original text: %s\n", plaintext)
mac := auth.Sum([]byte(plaintext), &secretKey)
fmt.Printf("MAC: %x\n", *mac)
result := auth.Verify(mac[:], []byte(plaintext), &secretKey)
fmt.Println("Verified: ", result)
badResult := auth.Verify(mac[:], []byte("wrong message"), &secretKey)
fmt.Println("Not verified: ", badResult)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment