...
1
2
3
4
5 package auth_test
6
7 import (
8 "encoding/hex"
9 "fmt"
10
11 "golang.org/x/crypto/nacl/auth"
12 )
13
14 func Example() {
15
16
17
18
19 secretKeyBytes, err := hex.DecodeString("6368616e676520746869732070617373776f726420746f206120736563726574")
20 if err != nil {
21 panic(err)
22 }
23
24 var secretKey [32]byte
25 copy(secretKey[:], secretKeyBytes)
26
27 mac := auth.Sum([]byte("hello world"), &secretKey)
28 fmt.Printf("%x\n", *mac)
29 result := auth.Verify(mac[:], []byte("hello world"), &secretKey)
30 fmt.Println(result)
31 badResult := auth.Verify(mac[:], []byte("different message"), &secretKey)
32 fmt.Println(badResult)
33
34
35
36 }
37
View as plain text