From dc85c97f3730b066f3603081d21df67349f9a84d Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Sat, 30 Dec 2023 15:49:47 +0100 Subject: Add command for generating ED25519 keypairs --- cmd/gitolfs3-gen-ed25519-key/main.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 cmd/gitolfs3-gen-ed25519-key/main.go (limited to 'cmd/gitolfs3-gen-ed25519-key/main.go') diff --git a/cmd/gitolfs3-gen-ed25519-key/main.go b/cmd/gitolfs3-gen-ed25519-key/main.go new file mode 100644 index 0000000..8288fd1 --- /dev/null +++ b/cmd/gitolfs3-gen-ed25519-key/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "crypto/ed25519" + "crypto/rand" + "encoding/hex" + "fmt" + "os" +) + +func wipe(b []byte) { + for i := range b { + b[i] = 0 + } +} + +func main() { + publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader) + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to generate ED25519 key: %s", err) + os.Exit(1) + } + defer wipe(privateKey) + + enc := hex.NewEncoder(os.Stdout) + print("Public ") + enc.Write(publicKey) + print("\nPrivate ") + enc.Write(privateKey.Seed()) + println() +} -- cgit v1.2.3