-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (51 loc) · 1.22 KB
/
main.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
58
package main
import (
"flag"
"fmt"
"log"
"simplepwd/crypto"
"simplepwd/useful"
"syscall"
"golang.org/x/crypto/ssh/terminal"
)
var (
filename *string
password *string
dec *bool
chgpw *bool
)
func main() {
filename = flag.String("f", "", "File path of passwords")
password = flag.String("p", "", "Master password of file")
dec = flag.Bool("d", false, "Decrypt file and print content")
chgpw = flag.Bool("c", false, "Change Passowrd")
flag.Parse()
if useful.FileExist(*filename) {
// file exists, decrypt file content
if *password == "" {
fmt.Println("Please Enter Password")
bytePw, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
log.Fatal(err.Error())
}
*password = string(bytePw)
}
data := crypto.DecryptFile(*filename, *password)
if *dec {
fmt.Println(string(*data))
return
}
if *chgpw {
fmt.Println("Please Enter New Password")
bytePw, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
log.Fatal(err.Error())
}
crypto.EncryptFile(*filename, data, string(bytePw))
}
repl(data)
} else {
// file doesnt exist, create file
useful.CreateFile(*filename)
}
}