summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLevi Durfee <levi.durfee@gmail.com>2026-01-06 18:33:28 -0500
committerLevi Durfee <levi.durfee@gmail.com>2026-01-06 18:55:09 -0500
commit452911586df6115a7c8deadee87fe5d97a7fe36f (patch)
tree6e0979813a7106a36b46e4ca1e289fa35049c969
parent7a3184afc17a267a2a140e6ab95d7fe57f91cb69 (diff)
Add urfave cli
-rw-r--r--Makefile4
-rw-r--r--cmd/goaes/commands/generate.go21
-rw-r--r--cmd/goaes/main.go32
-rw-r--r--go.mod2
-rw-r--r--go.sum10
-rw-r--r--internal/goaes.go15
-rw-r--r--internal/internal.go21
7 files changed, 103 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 4172c03..7620a98 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
.PHONY: run build
-run:
- CGO_ENABLED=0 go run ./main.go
+build:
+ CGO_ENABLED=0 go build -o ./goaes ./cmd/goaes
diff --git a/cmd/goaes/commands/generate.go b/cmd/goaes/commands/generate.go
new file mode 100644
index 0000000..2ce2400
--- /dev/null
+++ b/cmd/goaes/commands/generate.go
@@ -0,0 +1,21 @@
+package commands
+
+import (
+ "context"
+ "encoding/base64"
+ "fmt"
+
+ "github.com/nerdsec/goaes/internal"
+ "github.com/urfave/cli/v3"
+)
+
+func Generate(ctx context.Context, cmd *cli.Command) error {
+ key, err := internal.NewDEK()
+ if err != nil {
+ return err
+ }
+
+ fmt.Println(base64.StdEncoding.EncodeToString(key))
+
+ return nil
+}
diff --git a/cmd/goaes/main.go b/cmd/goaes/main.go
new file mode 100644
index 0000000..30f1d1d
--- /dev/null
+++ b/cmd/goaes/main.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+ "context"
+ "log"
+ "os"
+
+ "github.com/nerdsec/goaes/cmd/goaes/commands"
+ "github.com/urfave/cli/v3"
+)
+
+func main() {
+ cmd := &cli.Command{
+ Name: "goaes",
+ Usage: "Simple AES encryption built with Go",
+ Action: func(ctx context.Context, cmd *cli.Command) error {
+ return cli.DefaultShowRootCommandHelp(cmd)
+ },
+ Commands: []*cli.Command{
+ {
+ Name: "generate",
+ Aliases: []string{"g"},
+ Usage: "Generate a base64 encoded key",
+ Action: commands.Generate,
+ },
+ },
+ }
+
+ if err := cmd.Run(context.Background(), os.Args); err != nil {
+ log.Fatal(err)
+ }
+}
diff --git a/go.mod b/go.mod
index d39f532..c296c32 100644
--- a/go.mod
+++ b/go.mod
@@ -3,3 +3,5 @@ module github.com/nerdsec/goaes
go 1.25.0
require github.com/joho/godotenv v1.5.1
+
+require github.com/urfave/cli/v3 v3.6.1
diff --git a/go.sum b/go.sum
index d61b19e..e648845 100644
--- a/go.sum
+++ b/go.sum
@@ -1,2 +1,12 @@
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
+github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
+github.com/urfave/cli/v3 v3.6.1 h1:j8Qq8NyUawj/7rTYdBGrxcH7A/j7/G8Q5LhWEW4G3Mo=
+github.com/urfave/cli/v3 v3.6.1/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/internal/goaes.go b/internal/goaes.go
new file mode 100644
index 0000000..668ef17
--- /dev/null
+++ b/internal/goaes.go
@@ -0,0 +1,15 @@
+package internal
+
+import (
+ "crypto/rand"
+ "fmt"
+ "io"
+)
+
+func NewDEK() (DEK, error) {
+ key := make([]byte, 32) // AES-256
+ if _, err := io.ReadFull(rand.Reader, key); err != nil {
+ return nil, fmt.Errorf("random DEK gen: %w", err)
+ }
+ return DEK(key), nil
+}
diff --git a/internal/internal.go b/internal/internal.go
new file mode 100644
index 0000000..970232c
--- /dev/null
+++ b/internal/internal.go
@@ -0,0 +1,21 @@
+package internal
+
+import "errors"
+
+type (
+ KEK []byte
+ DEK []byte
+ WrappedDEK []byte
+ Ciphertext []byte
+)
+
+type EncryptedDataPayload struct {
+ DEK WrappedDEK
+ Payload Ciphertext
+}
+
+var (
+ aadWrapDEK = []byte("wrap:dek:v1")
+ aadDataMsg = []byte("data:msg:v1")
+ errBadKeyLn = errors.New("invalid key length: must be 16, 24, or 32 bytes")
+)