diff options
author | Rutger Broekhoff | 2023-12-30 15:49:47 +0100 |
---|---|---|
committer | Rutger Broekhoff | 2023-12-30 15:49:47 +0100 |
commit | dc85c97f3730b066f3603081d21df67349f9a84d (patch) | |
tree | cf4b3af533ddd9cfec39dee4a1c36a93eeed7013 | |
parent | a8726abf0b61327190204446974c073d8a64f102 (diff) | |
download | gitolfs3-dc85c97f3730b066f3603081d21df67349f9a84d.tar.gz gitolfs3-dc85c97f3730b066f3603081d21df67349f9a84d.zip |
Add command for generating ED25519 keypairs
-rw-r--r-- | cmd/gitolfs3-gen-ed25519-key/main.go | 31 |
1 files changed, 31 insertions, 0 deletions
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 @@ | |||
1 | package main | ||
2 | |||
3 | import ( | ||
4 | "crypto/ed25519" | ||
5 | "crypto/rand" | ||
6 | "encoding/hex" | ||
7 | "fmt" | ||
8 | "os" | ||
9 | ) | ||
10 | |||
11 | func wipe(b []byte) { | ||
12 | for i := range b { | ||
13 | b[i] = 0 | ||
14 | } | ||
15 | } | ||
16 | |||
17 | func main() { | ||
18 | publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader) | ||
19 | if err != nil { | ||
20 | fmt.Fprintf(os.Stderr, "Failed to generate ED25519 key: %s", err) | ||
21 | os.Exit(1) | ||
22 | } | ||
23 | defer wipe(privateKey) | ||
24 | |||
25 | enc := hex.NewEncoder(os.Stdout) | ||
26 | print("Public ") | ||
27 | enc.Write(publicKey) | ||
28 | print("\nPrivate ") | ||
29 | enc.Write(privateKey.Seed()) | ||
30 | println() | ||
31 | } | ||