xref: /aosp_15_r20/external/tink/go/prf/prf_test.go (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1// Copyright 2020 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15////////////////////////////////////////////////////////////////////////////////
16
17package prf_test
18
19import (
20	"encoding/base64"
21	"fmt"
22	"log"
23
24	"github.com/google/tink/go/keyset"
25	"github.com/google/tink/go/prf"
26)
27
28func Example() {
29	kh, err := keyset.NewHandle(prf.HMACSHA256PRFKeyTemplate())
30	if err != nil {
31		log.Fatal(err)
32	}
33
34	// TODO: save the keyset to a safe location. DO NOT hardcode it in source code.
35	// Consider encrypting it with a remote key in Cloud KMS, AWS KMS or HashiCorp Vault.
36	// See https://github.com/google/tink/blob/master/docs/GOLANG-HOWTO.md#storing-and-loading-existing-keysets.
37
38	ps, err := prf.NewPRFSet(kh)
39	if err != nil {
40		log.Fatal(err)
41	}
42
43	msg := []byte("This is an ID needs to be redacted")
44	output, err := ps.ComputePrimaryPRF(msg, 16)
45
46	fmt.Printf("Message: %s\n", msg)
47	fmt.Printf("Redacted: %s\n", base64.StdEncoding.EncodeToString(output))
48}
49