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

Function ExampleNewWriter

armor/armor_test.go:26–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24)
25
26func ExampleNewWriter() {
27 publicKey := "age1cy0su9fwf3gf9mw868g5yut09p6nytfmmnktexz2ya5uqg9vl9sss4euqm"
28 recipient, err := age.ParseX25519Recipient(publicKey)
29 if err != nil {
30 log.Fatalf("Failed to parse public key %q: %v", publicKey, err)
31 }
32
33 buf := &bytes.Buffer{}
34 armorWriter := armor.NewWriter(buf)
35
36 w, err := age.Encrypt(armorWriter, recipient)
37 if err != nil {
38 log.Fatalf("Failed to create encrypted file: %v", err)
39 }
40 if _, err := io.WriteString(w, "Black lives matter."); err != nil {
41 log.Fatalf("Failed to write to encrypted file: %v", err)
42 }
43 if err := w.Close(); err != nil {
44 log.Fatalf("Failed to close encrypted file: %v", err)
45 }
46
47 if err := armorWriter.Close(); err != nil {
48 log.Fatalf("Failed to close armor: %v", err)
49 }
50
51 fmt.Printf("%s[...]", buf.Bytes()[:35])
52 // Output:
53 // -----BEGIN AGE ENCRYPTED FILE-----
54 // [...]
55}
56
57var privateKey = "AGE-SECRET-KEY-184JMZMVQH3E6U0PSL869004Y3U2NYV7R30EU99CSEDNPH02YUVFSZW44VU"
58

Callers

nothing calls this directly

Calls 5

ParseX25519RecipientFunction · 0.92
NewWriterFunction · 0.92
EncryptFunction · 0.92
BytesMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…