-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_privkey_from_strings.go
57 lines (47 loc) · 1.12 KB
/
gen_privkey_from_strings.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
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"context"
"crypto/sha256"
"encoding/hex"
"flag"
"fmt"
"strings"
)
type GenPrivkeyFromStringsCmd struct {
cmd string
flagSet *flag.FlagSet
text *string
}
func NewGenPrivkeyFromStringsCmd() *GenPrivkeyFromStringsCmd {
return &GenPrivkeyFromStringsCmd{}
}
func (cmd *GenPrivkeyFromStringsCmd) Command() string {
return cmd.cmd
}
func (cmd *GenPrivkeyFromStringsCmd) Parse(args []string) {
cmd.flagSet.Parse(args)
}
func (cmd *GenPrivkeyFromStringsCmd) Init() {
cmd.cmd = "genprivkeyfromstrings"
cmd.flagSet = flag.NewFlagSet(cmd.cmd, flag.ExitOnError)
cmd.text = cmd.flagSet.String("text", "", "aaa|bbb|ccc")
}
func (cmd *GenPrivkeyFromStringsCmd) GetFlagSet() *flag.FlagSet {
return cmd.flagSet
}
func (cmd *GenPrivkeyFromStringsCmd) Do(ctx context.Context) {
texts := strings.Split(*cmd.text, "|")
seed := ""
for i, w := range texts {
fmt.Printf("%d: '%s'\n", i, w)
seed = seed + strings.Trim(w, " ")
}
h := sha256.New()
_, err := h.Write([]byte(seed))
if err != nil {
fmt.Println(err)
return
}
privkey := hex.EncodeToString(h.Sum(nil))
fmt.Printf("privkey: '%s'\n", privkey)
}