WIP
This commit is contained in:
parent
91f7cbbd06
commit
3dba047793
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/.idea/
|
||||
/.idea/
|
||||
/simple-privacy-tool
|
||||
@ -1,6 +1,8 @@
|
||||
package spt
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
rootCmd = &cobra.Command{
|
||||
@ -29,6 +31,18 @@ func init() {
|
||||
|
||||
func encrypt(cmd *cobra.Command, args []string) error {
|
||||
//TODO: implementation
|
||||
|
||||
//// this is the sample of reading password
|
||||
//fmt.Print("input passphrase: ")
|
||||
//passwd, err := privacy.ReadPassword()
|
||||
//if err != nil {
|
||||
// return err
|
||||
//}
|
||||
//fmt.Println()
|
||||
//
|
||||
//fmt.Printf("password: %s\n", passwd)
|
||||
//// end of sample
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
6
go.mod
6
go.mod
@ -2,8 +2,12 @@ module gitea.suyono.dev/suyono/simple-privacy-tool
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/spf13/cobra v1.7.0
|
||||
|
||||
require (
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/spf13/cobra v1.7.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
golang.org/x/crypto v0.11.0 // indirect
|
||||
golang.org/x/sys v0.10.0 // indirect
|
||||
golang.org/x/term v0.10.0 // indirect
|
||||
)
|
||||
|
||||
6
go.sum
6
go.sum
@ -6,5 +6,11 @@ github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
||||
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
|
||||
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
10
main.go
10
main.go
@ -1,5 +1,13 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.suyono.dev/suyono/simple-privacy-tool/cmd/spt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := spt.Execute()
|
||||
if err != nil {
|
||||
fmt.Printf("error: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
35
privacy/privacy.go
Normal file
35
privacy/privacy.go
Normal file
@ -0,0 +1,35 @@
|
||||
package privacy
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"golang.org/x/crypto/argon2"
|
||||
"golang.org/x/term"
|
||||
"os"
|
||||
)
|
||||
|
||||
func GenerateKey(password string) ([]byte, error) {
|
||||
salt := make([]byte, 16)
|
||||
_, err := rand.Read(salt[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
key := argon2.IDKey([]byte(password), salt, 1, 16*1024, 4, 32)
|
||||
|
||||
return key, nil
|
||||
}
|
||||
|
||||
func ReadPasswordFromTerminal() (string, error) {
|
||||
var inputFd int = int(os.Stdin.Fd())
|
||||
if !term.IsTerminal(inputFd) {
|
||||
return "", errors.New("not a terminal")
|
||||
}
|
||||
|
||||
passwd, err := term.ReadPassword(inputFd)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(passwd), nil
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user