Golang code-google-com-p-go-crypto-ssh-terminal.ReadPassword类(方法)实例源码

下面列出了Golang code-google-com-p-go-crypto-ssh-terminal.ReadPassword 类(方法)源码代码实例,从而了解它的用法。

作者:gak    项目:1pas   
func createNewVault(path string, lowSecurity bool) {
	if !strings.HasSuffix(path, ".agilekeychain") {
		path += ".agilekeychain"
	}
	fmt.Printf("Creating new vault in %s\n", path)
	fmt.Printf("Enter master password: ")
	masterPwd, err := terminal.ReadPassword(0)
	fmt.Printf("\nRe-enter master password: ")
	masterPwd2, _ := terminal.ReadPassword(0)
	if !bytes.Equal(masterPwd, masterPwd2) {
		fatalErr(nil, "Passwords do not match")
	}

	security := onepass.VaultSecurity{MasterPwd: string(masterPwd)}
	if lowSecurity {
		// use fewer PBKDF2 iterations to speed up
		// master key decryption
		security.Iterations = 10
	}

	_, err = onepass.NewVault(path, security)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create new vault: %v", err)
	}
}

作者:dieyush    项目:zzke   
func createPasswd() {
	_, err := os.Stat(KEY_ROOT_PASSWD)
	if err != nil {
		fmt.Printf("This is your first time working with zzkey\n")
		fmt.Printf("Please input a password to protect your infomation\n")
	}

	fmt.Printf("Password :")
	buf, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
	fmt.Printf("\n")
	fmt.Printf("Repeat :")
	buf1, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
	fmt.Printf("\n")
	if string(buf) != string(buf1) {
		fmt.Printf("not match\n")
		return
	}

	password = string(buf)
	buf2 := string(buf) + "--salt add by zzkey--"
	h := sha1.New()
	io.WriteString(h, buf2)
	buf2 = fmt.Sprintf("%x", h.Sum(nil))
	ioutil.WriteFile(KEY_ROOT_PASSWD, []byte(buf2), 0600)
	fmt.Println("Password has been set,Having Fun With zzkey!")
}

作者:dieyush    项目:zzke   
func setRecord(p string) {
	if e := getRecord(p); e == nil {
		fmt.Fprintf(os.Stderr, "record already exists\n")
		return
	}

	fmt.Printf("use random password ?\n[y/n] ")
	ra := bufio.NewReader(os.Stdin)
	uinput, _, _ := ra.ReadLine()
	var setpass string
	if string(uinput) == "y" {
		pass := randomPasswd(16)
		fmt.Printf("random password : %s\n", pass)
		setpass = pass
	} else {
		fmt.Printf("%s's Password :", p)
		pass, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
		fmt.Printf("\n")

		fmt.Printf("Repeat Password :")
		passagain, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
		fmt.Printf("\n")

		if string(pass) != string(passagain) {
			fmt.Fprintf(os.Stderr, "not match\n")
			return
		}
		setpass = string(pass)
	}

	fmt.Printf("%s's Description : ", p)
	r := bufio.NewReader(os.Stdin)
	input, _, _ := r.ReadLine()
	description := string(input)

	i := Info{p, string(setpass), string(description)}
	j, _ := json.Marshal(i)
	j = append(j, '\n')

	content := string(j)
	_, err := os.Stat(KEY_ROOT_DB)
	if err == nil {
		buf, _ := ioutil.ReadFile(KEY_ROOT_DB)
		content = decryptFromBase64(string(buf), password)
		content += string(j)
	}
	k := encryptToBase64(content, password)
	if e := ioutil.WriteFile(KEY_ROOT_DB, []byte(k), 0600); e != nil {
		fmt.Fprintf(os.Stderr, "add record failed")
	}

	fmt.Printf("record add to the database\n")
}

作者:karthikkeya    项目:logfingjir   
func fetchPass() *string {
	fmt.Print("Enter Password: ")
	passwordByte, _ := terminal.ReadPassword(0)
	password := string(passwordByte)
	password = strings.TrimSpace(password)
	return &password
}

作者:gota    项目:kit   
// handleGetPass reads a line of input from a terminal without local echo.
func handleGetPass(r *Request) (interface{}, error) {
	fmt.Print(r.Args.One().MustString())
	data, err := terminal.ReadPassword(0) // stdin
	fmt.Println()
	if err != nil {
		return nil, err
	}
	return string(data), nil
}

作者:reth    项目:mol   
func readpass(prompt string) string {
	fmt.Printf(prompt)
	bs, err := terminal.ReadPassword(int(os.Stdin.Fd()))
	if err != nil {
		return ""
	}
	fmt.Println()
	return string(bs)
}

作者:gak    项目:1pas   
func setPassword(vault *onepass.Vault, currentPwd string) {
	// TODO - Prompt for hint and save that to the .password.hint file
	fmt.Printf("New master password: ")
	newPwd, err := terminal.ReadPassword(0)
	fmt.Printf("\nRe-enter new master password: ")
	newPwd2, err := terminal.ReadPassword(0)
	fmt.Println()
	if !bytes.Equal(newPwd, newPwd2) {
		fatalErr(nil, "Passwords do not match")
	}
	err = vault.SetMasterPassword(currentPwd, string(newPwd))
	if err != nil {
		fatalErr(err, "Failed to change master password")
	}

	fmt.Printf("The master password has been updated.\n\n")
	fmt.Printf(setPasswordSyncNote)
}

作者:hdonna    项目:vault   
func getPassphrase(prompt string) []byte {
	var h hash.Hash = sha512.New384()
	fmt.Fprintf(os.Stdout, prompt)
	phrase, err := terminal.ReadPassword(int(os.Stdin.Fd()))
	fmt.Fprintf(os.Stdout, "\n")
	if err != nil {
		log.Fatal(err)
	}
	io.Copy(h, bytes.NewReader(phrase))
	return h.Sum(nil)
}

作者:gak    项目:1pas   
func readNewPassword(passType string) (string, error) {
	fmt.Printf("%s (or '-' for a random new %s): ", passType, passType)
	pwd, _ := terminal.ReadPassword(0)
	if len(pwd) == 0 {
		fmt.Println()
		return "", nil
	}
	if string(pwd) == "-" {
		pwd = []byte(genDefaultPassword())
		fmt.Printf("(Random new password generated)")
	} else {
		fmt.Printf("\nRe-enter %s: ", passType)
		pwd2, _ := terminal.ReadPassword(0)
		if string(pwd) != string(pwd2) {
			return "", fmt.Errorf("Passwords do not match")
		}
	}
	fmt.Println()
	return string(pwd), nil
}

作者:ringer    项目:decrypt-windows-ec2-passw   
func main() {
	if len(os.Args) != 3 {
		fmt.Fprintf(os.Stderr, "Usage: %s <path to private key> <encrypted password>\n", os.Args[0])
		os.Exit(1)
	}
	pemPath := os.Args[1]
	encryptedPasswdB64 := os.Args[2]

	encryptedPasswd, err := base64.StdEncoding.DecodeString(encryptedPasswdB64)
	if err != nil {
		panic(err)
	}

	pemBytes, err := ioutil.ReadFile(pemPath)
	if err != nil {
		panic(err)
	}

	block, _ := pem.Decode(pemBytes)
	var asn1Bytes []byte
	if _, ok := block.Headers["DEK-Info"]; ok {
		fmt.Printf("Encrypted private key. Please enter passphrase: ")
		password, err := terminal.ReadPassword(0)
		fmt.Printf("\n")
		if err != nil {
			panic(err)
		}

		asn1Bytes, err = x509.DecryptPEMBlock(block, password)
		if err != nil {
			panic(err)
		}
	} else {
		asn1Bytes = block.Bytes
	}

	key, err := x509.ParsePKCS1PrivateKey(asn1Bytes)
	if err != nil {
		panic(err)
	}

	out, err := rsa.DecryptPKCS1v15(nil, key, encryptedPasswd)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Decrypted password: %s\n", string(out))
}

作者:dieyush    项目:zzke   
func changePasswd() {
	fmt.Printf("current password :")
	currentPass, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
	fmt.Printf("\n")
	if string(currentPass) != password {
		fmt.Fprintf(os.Stderr, "password error\n")
		return
	}
	createPasswd()
	buf, _ := ioutil.ReadFile(KEY_ROOT_DB)
	data := decryptFromBase64(string(buf), string(currentPass))

	k := encryptToBase64(data, password)
	ioutil.WriteFile(KEY_ROOT_DB, []byte(k), 0600)
	fmt.Printf("password changed\n")
}

作者:dieyush    项目:zzke   
func verifyPasswd() (p string, e error) {
	buf, _ := ioutil.ReadFile(KEY_ROOT_PASSWD)
	fmt.Printf("Password :")
	pass, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
	fmt.Printf("\n")
	pass2 := string(pass) + "--salt add by zzkey--"
	h := sha1.New()
	io.WriteString(h, pass2)
	pass2 = fmt.Sprintf("%x", h.Sum(nil))
	if pass2 == string(buf) {
		p, e = pass2, nil
		password = string(pass)
		return
	}
	p, e = "", errors.New("Wrong Password")
	return
}

作者:vonwen    项目:shamir-secret-sharing-schem   
func main() {
	input, err := terminal.ReadPassword(0)

	if err != nil {
		panic(err)
	}

	secret := string(input)
	parts := EasySplit(secret, 6, 3)

	fmt.Println(parts)

	newshares := []string{parts[1], parts[2], parts[5]}
	result := EasyJoin(newshares)

	fmt.Println(result)
}

作者:rualatngu    项目:tsur   
func passwordFromReader(reader io.Reader) (string, error) {
	var (
		password []byte
		err      error
	)
	if file, ok := reader.(*os.File); ok && terminal.IsTerminal(int(file.Fd())) {
		password, err = terminal.ReadPassword(int(file.Fd()))
		if err != nil {
			return "", err
		}
	} else {
		fmt.Fscanf(reader, "%s\n", &password)
	}
	if len(password) == 0 {
		msg := "You must provide the password!"
		return "", errors.New(msg)
	}
	return string(password), err
}

作者:spladu    项目:underpant   
// Load the TLS certificate from the speciified files. The key file can be an encryped
// PEM so long as it carries the appropriate headers (Proc-Type and Dek-Info) and the
// password will be requested interactively.
func LoadCertificate(crtFile, keyFile string) (tls.Certificate, error) {
	crtBytes, err := ioutil.ReadFile(crtFile)
	if err != nil {
		return tls.Certificate{}, err
	}

	keyBytes, err := ioutil.ReadFile(keyFile)
	if err != nil {
		return tls.Certificate{}, err
	}

	keyDer, _ := pem.Decode(keyBytes)
	if keyDer == nil {
		return tls.Certificate{}, fmt.Errorf("%s cannot be decoded.", keyFile)
	}

	// http://www.ietf.org/rfc/rfc1421.txt
	if !strings.HasPrefix(keyDer.Headers["Proc-Type"], "4,ENCRYPTED") {
		return tls.X509KeyPair(crtBytes, keyBytes)
	}

	fmt.Printf("%s\nPassword: ", keyFile)
	pwd, err := terminal.ReadPassword(int(os.Stdin.Fd()))
	fmt.Println()
	if err != nil {
		return tls.Certificate{}, err
	}

	keyDec, err := x509.DecryptPEMBlock(keyDer, pwd)
	if err != nil {
		return tls.Certificate{}, err
	}

	return tls.X509KeyPair(crtBytes, pem.EncodeToMemory(&pem.Block{
		Type:    "RSA PRIVATE KEY",
		Headers: map[string]string{},
		Bytes:   keyDec,
	}))
}

作者:hdonna    项目:saltct   
func login(reauth bool) {
	if reauth {
		type arg struct {
			Eauth    string `json:"eauth"`
			Username string `json:"username"`
			Password string `json:"password"`
		}
		type ret struct {
			Token  string
			Start  float64
			Expire float64
			User   string
			Eauth  string
			Perms  []string
		}
		var req *http.Request
		var res *http.Response
		c := &http.Client{Jar: jar}

		fmt.Fprintf(os.Stdout, "Password: ")
		pass, err := terminal.ReadPassword(int(os.Stdin.Fd()))
		fmt.Fprintf(os.Stdout, "\n")

		// prompt for pass
		b, err := json.Marshal(&arg{*eauth, *user, string(pass)})
		req = mkReq("POST", "login", &b)
		res, err = c.Do(req)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error: %v\n", err)
			os.Exit(1)
		}
		if res.StatusCode == http.StatusUnauthorized {
			fmt.Fprintf(os.Stderr, "Authentication failed.\n")
			os.Exit(2)
		}
		//fmt.Fprintf(os.Stderr, "debug: %+v\n", res)
		//fmt.Fprintf(os.Stderr, "debug: %+v\n", res.Body)
		d := json.NewDecoder(res.Body)
		var resp map[string][]ret
		err = d.Decode(&resp)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error: %+v\n", err)
		}
		//fmt.Fprintf(os.Stderr, "debug: login response: %+v\n", resp)
		auth = resp["return"][0].Token
	} else {
		var token string = fmt.Sprintf("%s/token", *configDir)
		// Look for an existing token
		fi, err := os.Stat(*configDir)
		if err != nil || !fi.IsDir() {
			os.MkdirAll(*configDir, 0700)
		}
		_, err = os.Stat(token)
		if err != nil {
			fmt.Fprintf(os.Stderr, "info: no token found\n")
		} else {
			f, err := os.Open(token)
			if err != nil {
				fmt.Fprintf(os.Stderr, "error: %v\n", err)
				os.Exit(1)
			}
			d := json.NewDecoder(f)
			d.Decode(&auth)
			f.Close()
		}
		jar.SetCookies(serverUrl, []*http.Cookie{&http.Cookie{Name: "session_id", Value: auth}})
	}
	//fmt.Fprintf(os.Stderr, "info: token: %s\n", auth)
}

作者:General-Bec    项目:snapp   
func xreadPassword(fd int) ([]byte, error) {
	return terminal.ReadPassword(fd)
}

作者:nic    项目:pon   
func do() bool {
	if err := system.IsSafe(); err != nil {
		fmt.Fprintf(os.Stderr, "System checks failed: %s\n", err)
		return false
	}

	editor := os.Getenv("EDITOR")
	if len(editor) == 0 {
		fmt.Fprintf(os.Stderr, "$EDITOR is not set\n")
		return false
	}

	stateFile := &disk.StateFile{
		Path: *stateFileName,
		Rand: crypto_rand.Reader,
		Log: func(format string, args ...interface{}) {
			fmt.Fprintf(os.Stderr, format, args...)
		},
	}

	stateLock, err := stateFile.Lock(false /* don't create */)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Cannot open state file: %s\n", err)
		return false
	}
	if stateLock == nil {
		fmt.Fprintf(os.Stderr, "Cannot obtain lock on state file\n")
		return false
	}
	defer stateLock.Close()

	var state *disk.State
	var passphrase string
	for {
		state, err = stateFile.Read(passphrase)
		if err == nil {
			break
		}
		if err != disk.BadPasswordError {
			fmt.Fprintf(os.Stderr, "Failed to decrypt state file: %s\n", err)
			return false
		}

		fmt.Fprintf(os.Stderr, "Passphrase: ")
		passphraseBytes, err := terminal.ReadPassword(0)
		fmt.Fprintf(os.Stderr, "\n")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to read password\n")
			return false
		}
		passphrase = string(passphraseBytes)
	}

	tempDir, err := system.SafeTempDir()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to get safe temp directory: %s\n", err)
		return false
	}

	tempFile, err := ioutil.TempFile(tempDir, "pond-editstate-")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create temp file: %s\n", err)
		return false
	}
	tempFileName := tempFile.Name()
	defer func() {
		os.Remove(tempFileName)
	}()

	signals := make(chan os.Signal, 8)
	signal.Notify(signals, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		<-signals
		println("Caught signal: removing", tempFileName)
		os.Remove(tempFileName)
		os.Exit(1)
	}()

	entities := serialise(tempFile, state)

	var newStateSerialized []byte
	for {
		cmd := exec.Command(editor, tempFileName)
		cmd.Stdin = os.Stdin
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr

		if err := cmd.Run(); err != nil {
			fmt.Fprintf(os.Stderr, "Failed to run editor: %s\n", err)
			return false
		}
		tempFile.Close()
		tempFile, err := os.Open(tempFileName)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to open temp file: %s\n", err)
			return false
		}

		newState := new(disk.State)
		err = parse(newState, tempFile, entities)
//.........这里部分代码省略.........

作者:wwitzel    项目:util   
func ReadPassword() (string, error) {
	fd := os.Stdin.Fd()
	pass, err := terminal.ReadPassword(int(fd))
	return string(pass), err
}

作者:radi    项目:pon   
func do() bool {
	if err := system.IsSafe(); err != nil {
		fmt.Fprintf(os.Stderr, "System checks failed: %s\n", err)
		return false
	}

	editor := os.Getenv("EDITOR")
	if len(editor) == 0 {
		fmt.Fprintf(os.Stderr, "$EDITOR is not set\n")
		return false
	}

	stateFile, err := os.Open(*stateFileName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to open state file: %s\n", err)
		return false
	}
	defer stateFile.Close()

	stateLock, ok := disk.LockStateFile(stateFile)
	if !ok {
		fmt.Fprintf(os.Stderr, "Cannot obtain lock on state file\n")
		return false
	}
	defer stateLock.Close()

	encrypted, err := ioutil.ReadAll(stateFile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to read state file: %s\n", err)
		return false
	}

	salt, ok := disk.GetSCryptSaltFromState(encrypted)
	if !ok {
		fmt.Fprintf(os.Stderr, "State file is too short to be valid\n")
		return false
	}

	var state *disk.State
	var key [32]byte

	for {
		state, err = disk.LoadState(encrypted, &key)
		if err == nil {
			break
		}
		if err != disk.BadPasswordError {
			fmt.Fprintf(os.Stderr, "Failed to decrypt state file: %s\n", err)
			return false
		}

		fmt.Fprintf(os.Stderr, "Passphrase: ")
		password, err := terminal.ReadPassword(0)
		fmt.Fprintf(os.Stderr, "\n")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to read password\n")
			return false
		}
		keySlice, err := disk.DeriveKey(string(password), &salt)
		copy(key[:], keySlice)
	}

	tempDir, err := system.SafeTempDir()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to get safe temp directory: %s\n", err)
		return false
	}

	tempFile, err := ioutil.TempFile(tempDir, "pond-editstate-")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create temp file: %s\n", err)
		return false
	}
	tempFileName := tempFile.Name()
	defer func() {
		os.Remove(tempFileName)
	}()

	signals := make(chan os.Signal, 8)
	signal.Notify(signals, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		<-signals
		println("Caught signal: removing", tempFileName)
		os.Remove(tempFileName)
		os.Exit(1)
	}()

	entities := serialise(tempFile, state)

	var newStateSerialized []byte
	for {
		cmd := exec.Command(editor, tempFileName)
		cmd.Stdin = os.Stdin
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr

		if err := cmd.Run(); err != nil {
			fmt.Fprintf(os.Stderr, "Failed to run editor: %s\n", err)
			return false
		}
//.........这里部分代码省略.........


问题


面经


文章

微信
公众号

扫码关注公众号