()
| 21 | ) |
| 22 | |
| 23 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…