Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ go get github.com/kevinburke/nacl

Or you can Git clone the code directly to $GOPATH/src/github.com/kevinburke/nacl.

#### Using `cmd`s

When used as scripts in modules (for e.g. automation) the shipped `cmd`s can
be called e.g. like this:

```
go run $(go list -m -f '{{.Dir}}' github.com/kevinburke/nacl)/cmd/nacl-generate-box-key/main.go
```

### Who am I?

While you probably shouldn't trust random security code from the Internet,
Expand Down
42 changes: 42 additions & 0 deletions cmd/nacl-box/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"flag"
"io"
"os"

"github.com/kevinburke/nacl"
"github.com/kevinburke/nacl/box"
)

var w = os.Stdout

func main() {

encrypt := flag.Bool("encrypt", false, "Encrypt (instead of decrypt)")
pubhex := flag.String("pubhex", "", "Public key in hex format")
privhex := flag.String("privhex", "", "Private key in hex format")
flag.Parse()
pub, err := nacl.Load(*pubhex)
if err != nil {
panic(err)
}
prv, err := nacl.Load(*privhex)
if err != nil {
panic(err)
}
buf, err := io.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
if *encrypt {
w.Write(box.EasySeal(buf, pub, prv))
} else {
out, err := box.EasyOpen(buf, pub, prv)
if err != nil {
panic(err)
}
w.Write((out))
}

}