diff options
| author | Levi Durfee <levi.durfee@gmail.com> | 2026-01-06 19:08:34 -0500 |
|---|---|---|
| committer | Levi Durfee <levi.durfee@gmail.com> | 2026-01-06 19:08:44 -0500 |
| commit | 35a6325ba12d0462bf01eb740fb6abde2d43c17a (patch) | |
| tree | e102dac429a78557ab4078d66bbd175d88b2d277 /cmd | |
| parent | 452911586df6115a7c8deadee87fe5d97a7fe36f (diff) | |
Add ability to encrypt files
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/goaes/commands/decrypt.go | 12 | ||||
| -rw-r--r-- | cmd/goaes/commands/encrypt.go | 38 | ||||
| -rw-r--r-- | cmd/goaes/main.go | 26 |
3 files changed, 76 insertions, 0 deletions
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, + }, }, } |
