MCPcopy Create free account
hub / github.com/google/go-cloud / Example

Function Example

secrets/example_test.go:28–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26)
27
28func Example() {
29 ctx := context.Background()
30
31 // Construct a *secrets.Keeper from one of the secrets subpackages.
32 // This example uses localsecrets.
33 sk, err := localsecrets.NewRandomKey()
34 if err != nil {
35 log.Fatal(err)
36 }
37 keeper := localsecrets.NewKeeper(sk)
38 defer keeper.Close()
39
40 // Now we can use keeper to Encrypt.
41 plaintext := []byte("Go CDK Secrets")
42 ciphertext, err := keeper.Encrypt(ctx, plaintext)
43 if err != nil {
44 log.Fatal(err)
45 }
46
47 // And/or Decrypt.
48 decrypted, err := keeper.Decrypt(ctx, ciphertext)
49 if err != nil {
50 log.Fatal(err)
51 }
52 fmt.Println(string(decrypted))
53
54 // Output:
55 // Go CDK Secrets
56}
57
58func Example_errorAs() {
59 // This example is specific to the gcpkms implementation; it

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
EncryptMethod · 0.95
DecryptMethod · 0.95
NewRandomKeyFunction · 0.92
NewKeeperFunction · 0.92

Tested by

no test coverage detected