-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
keys.go
45 lines (37 loc) · 980 Bytes
/
keys.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"bufio"
"fmt"
"os"
"strings"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
func genKey(opts *cmdOptions) {
if opts.Interface == "--help" || opts.Interface != "" || opts.Option != "" {
showSubCommandUsage("genkey", opts)
}
key, err := wgtypes.GeneratePrivateKey()
checkError(err)
fmt.Println(key.String())
}
func genPSK(opts *cmdOptions) {
if opts.Interface == "--help" || opts.Interface != "" || opts.Option != "" {
showSubCommandUsage("genpsk", opts)
}
key, err := wgtypes.GenerateKey()
checkError(err)
fmt.Println(key.String())
}
func pubKey(opts *cmdOptions) {
if opts.Interface == "--help" || opts.Interface != "" || opts.Option != "" {
showSubCommandUsage("pubkey", opts)
}
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
checkError(err)
input = strings.TrimSpace(input)
private, err := wgtypes.ParseKey(input)
checkError(err)
public := private.PublicKey()
fmt.Println(public.String())
}