1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 "golang.org/x/crypto/nacl/auth"
15 // Load your secret key from a safe place and reuse it across multiple
16 // Sum calls. (Obviously don't use this example key for anything
17 // real.) If you want to convert a passphrase to a key, use a suitable
18 // package like bcrypt or scrypt.
19 secretKeyBytes, err := hex.DecodeString("6368616e676520746869732070617373776f726420746f206120736563726574")
24 var secretKey [32]byte
25 copy(secretKey[:], secretKeyBytes)
27 mac := auth.Sum([]byte("hello world"), &secretKey)
28 fmt.Printf("%x\n", *mac)
29 result := auth.Verify(mac[:], []byte("hello world"), &secretKey)
31 badResult := auth.Verify(mac[:], []byte("different message"), &secretKey)
32 fmt.Println(badResult)
33 // Output: eca5a521f3d77b63f567fb0cb6f5f2d200641bc8dada42f60c5f881260c30317