This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142package crypto
import ( "bytes" "fmt" "io" "os"
"filippo.io/age")
// EncryptFile encrypts the given file using the given identitiesfunc EncryptFile(path string, recipients []age.Recipient) ([]byte, error) { data, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("failed to read file: %w", err) } return EncryptBytes(data, recipients)}
func EncryptBytes(data []byte, recipients []age.Recipient) ([]byte, error) {
src := bytes.NewReader(data) dst := new(bytes.Buffer)
enc, err := age.Encrypt(dst, recipients...) if err != nil { return nil, fmt.Errorf("initializing age enc failed: %w", err) }
if _, err := io.Copy(enc, src); err != nil { enc.Close() return nil, fmt.Errorf("encryption failed: %w", err) }
if err := enc.Close(); err != nil { return nil, fmt.Errorf("finalizing encryption failed: %w", err) }
return dst.Bytes(), nil}