()
| 26 | ) |
| 27 | |
| 28 | func 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 | |
| 58 | func Example_errorAs() { |
| 59 | // This example is specific to the gcpkms implementation; it |
nothing calls this directly
no test coverage detected