From 35a6325ba12d0462bf01eb740fb6abde2d43c17a Mon Sep 17 00:00:00 2001 From: Levi Durfee Date: Tue, 6 Jan 2026 19:08:34 -0500 Subject: Add ability to encrypt files --- cmd/goaes/commands/decrypt.go | 12 ++++++++++++ cmd/goaes/commands/encrypt.go | 38 ++++++++++++++++++++++++++++++++++++++ cmd/goaes/main.go | 26 ++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 cmd/goaes/commands/decrypt.go create mode 100644 cmd/goaes/commands/encrypt.go (limited to 'cmd/goaes') diff --git a/cmd/goaes/commands/decrypt.go b/cmd/goaes/commands/decrypt.go new file mode 100644 index 0000000..f89da22 --- /dev/null +++ b/cmd/goaes/commands/decrypt.go @@ -0,0 +1,12 @@ +package commands + +import ( + "context" + + "github.com/urfave/cli/v3" +) + +func Decrypt(ctx context.Context, cmd *cli.Command) error { + + return nil +} diff --git a/cmd/goaes/commands/encrypt.go b/cmd/goaes/commands/encrypt.go new file mode 100644 index 0000000..0c5d578 --- /dev/null +++ b/cmd/goaes/commands/encrypt.go @@ -0,0 +1,38 @@ +package commands + +import ( + "bytes" + "context" + "encoding/gob" + "os" + + "github.com/nerdsec/goaes/internal" + "github.com/urfave/cli/v3" +) + +func Encrypt(ctx context.Context, cmd *cli.Command) error { + source := cmd.String("source") + destination := cmd.String("destination") + + plaintext, err := os.ReadFile(source) + if err != nil { + return err + } + + payload, err := internal.Encrypt(plaintext) + if err != nil { + return err + } + + var dataBuffer bytes.Buffer + enc := gob.NewEncoder(&dataBuffer) + + err = enc.Encode(payload) + if err != nil { + return err + } + + os.WriteFile(destination, dataBuffer.Bytes(), 0666) + + return nil +} diff --git a/cmd/goaes/main.go b/cmd/goaes/main.go index 30f1d1d..f0b4368 100644 --- a/cmd/goaes/main.go +++ b/cmd/goaes/main.go @@ -23,6 +23,32 @@ func main() { Usage: "Generate a base64 encoded key", Action: commands.Generate, }, + { + Name: "encrypt", + Aliases: []string{"e"}, + Usage: "Encrypt a file", + Action: commands.Encrypt, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "source", + Aliases: []string{"s"}, + Usage: "source file to encrypt", + Required: true, + }, + &cli.StringFlag{ + Name: "destination", + Aliases: []string{"d"}, + Usage: "where to write the encrypted file", + Required: true, + }, + }, + }, + { + Name: "decrypt", + Aliases: []string{"d"}, + Usage: "Decrypt a file", + Action: commands.Decrypt, + }, }, } -- cgit v1.2.3