sophuwu.site > seks
made password invisible in terminal
sophuwu sophie@sophuwu.site
Sun, 15 Oct 2023 17:11:31 +0200
commit

f77ab8c6a2c27ed4ccd821bd77945c9e0c88a0c1

parent

efa8e666a934e4781a602374b32b255ff48609b1

3 files changed, 16 insertions(+), 20 deletions(-)

jump to
M go.modgo.mod

@@ -4,4 +4,7 @@ go 1.21.3

require golang.org/x/crypto v0.14.0 -require golang.org/x/sys v0.13.0 // indirect +require ( + golang.org/x/sys v0.13.0 // indirect + golang.org/x/term v0.13.0 // indirect +)
M go.sumgo.sum

@@ -2,3 +2,5 @@ golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=

golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
M main.gomain.go

@@ -9,8 +9,10 @@ "crypto/rand"

"crypto/sha256" "fmt" "golang.org/x/crypto/nacl/secretbox" + "golang.org/x/term" "os" "seks/sopHex" + "syscall" ) func ran() []byte {

@@ -60,19 +62,15 @@ } else {

fmt.Println("Usage: seks -e|-d") return } - fmt.Println("Enter password Your Password: ") - var r rune - var password []byte - for { - fmt.Scanf("%c", &r) - if r == '\n' { - break - } - password = append(password, byte(r)) + fmt.Print("Enter password Your Password: ") + password, err := term.ReadPassword(int(syscall.Stdin)) + if err != nil { + fmt.Println(err) + return } var buff bytes.Buffer - fmt.Println("Enter input data ending with EOF (Ctrl-D): ") - _, err := buff.ReadFrom(os.Stdin) + fmt.Printf("\nEnter input data ending with EOF (Ctrl-D):\n") + _, err = buff.ReadFrom(os.Stdin) if err != nil { fmt.Println(err) return

@@ -93,14 +91,7 @@ return

} result = decrypt(crypt, hashPasswd(crypt[0:32], password)) } - fmt.Println("Result: ") + fmt.Printf("-----Result-----\n") fmt.Println(result) - - // - // - //message := []byte("I like to eat apples and bananas. However, I do not like to eat oranges. Cars can drive!") - //encrypted := secretbox.Seal(salt, message, &nonce, &key) - - //fmt.Println(sopHex.Marshall(encrypted)) }