MCPcopy
hub / github.com/FiloSottile/age / ExampleEncrypt

Function ExampleEncrypt

age_test.go:23–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21)
22
23func ExampleEncrypt() {
24 publicKey := "age1cy0su9fwf3gf9mw868g5yut09p6nytfmmnktexz2ya5uqg9vl9sss4euqm"
25 recipient, err := age.ParseX25519Recipient(publicKey)
26 if err != nil {
27 log.Fatalf("Failed to parse public key %q: %v", publicKey, err)
28 }
29
30 out := &bytes.Buffer{}
31
32 w, err := age.Encrypt(out, recipient)
33 if err != nil {
34 log.Fatalf("Failed to create encrypted file: %v", err)
35 }
36 if _, err := io.WriteString(w, "Black lives matter."); err != nil {
37 log.Fatalf("Failed to write to encrypted file: %v", err)
38 }
39 if err := w.Close(); err != nil {
40 log.Fatalf("Failed to close encrypted file: %v", err)
41 }
42
43 fmt.Printf("Encrypted file size: %d\n", out.Len())
44 // Output:
45 // Encrypted file size: 219
46}
47
48// DO NOT hardcode the private key. Store it in a secret storage solution,
49// on disk if the local machine is trusted, or have the user provide it.

Callers

nothing calls this directly

Calls 3

ParseX25519RecipientFunction · 0.92
EncryptFunction · 0.92
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…