Created
November 23, 2019 10:50
-
-
Save hugows/7aa6d70451dd475daf3831cec98fa30f to your computer and use it in GitHub Desktop.
Alternative to jwt-go
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 ( | |
"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