cli-controlled encryption
This commit is contained in:
parent
c21833fcf0
commit
3c6920df6b
39
main.go
39
main.go
|
@ -9,6 +9,8 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"syscall"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
|
||||
func checkErr(err error) {
|
||||
|
@ -63,9 +65,10 @@ func getMode() string {
|
|||
var mode string
|
||||
fmt.Print("mode: ")
|
||||
fmt.Fscan(os.Stdin, &mode)
|
||||
if mode == "q" {os.Exit(1)}
|
||||
if mode != "h" && mode != "s" {
|
||||
fmt.Println("not a mode")
|
||||
fmt.Println("type 'h' for hide or 's' for show")
|
||||
fmt.Println("type 'h' for hide, 's' for show or 'q' to quit")
|
||||
mode = getMode()
|
||||
}
|
||||
return mode
|
||||
|
@ -88,11 +91,43 @@ func readFn() string {
|
|||
return filename
|
||||
}
|
||||
|
||||
func readPass() string {
|
||||
pw, err := terminal.ReadPassword(int(syscall.Stdin))
|
||||
checkErr(err)
|
||||
return string(pw)
|
||||
}
|
||||
|
||||
func checkPass() string {
|
||||
var pw string
|
||||
fmt.Print("password: ")
|
||||
pw1 := readPass()
|
||||
fmt.Print("\nagain: ")
|
||||
pw2 := readPass()
|
||||
fmt.Print("\n")
|
||||
if pw1 == pw2 {
|
||||
pw = pw1
|
||||
} else {
|
||||
fmt.Println("passwords don't match")
|
||||
checkPass()
|
||||
}
|
||||
return pw
|
||||
}
|
||||
|
||||
func main() {
|
||||
fn := readFn()
|
||||
fmt.Println(fn)
|
||||
mode := getMode()
|
||||
fmt.Println(mode)
|
||||
switch mode {
|
||||
case "h":
|
||||
pw := checkPass()
|
||||
key := keyMkr(pw)
|
||||
data := file2data(fn)
|
||||
secret := encrypt(data,key)
|
||||
secretfn := fn + ".hdn"
|
||||
data2file(secretfn,secret)
|
||||
case "s":
|
||||
fmt.Println("decrypt")
|
||||
}
|
||||
/*
|
||||
var passwd string = "ThisAnnPassphrase"
|
||||
fmt.Println(passwd)
|
||||
|
|
Loading…
Reference in New Issue