本文整理汇总了Golang中code/google/com/p/go/crypto/ssh/terminal.ReadPassword函数的典型用法代码示例。如果您正苦于以下问题:Golang ReadPassword函数的具体用法?Golang ReadPassword怎么用?Golang ReadPassword使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReadPassword函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createNewVault
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)
}
}
示例2: createPasswd
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!")
}
示例3: setRecord
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")
}
示例4: fetchPass
func fetchPass() *string {
fmt.Print("Enter Password: ")
passwordByte, _ := terminal.ReadPassword(0)
password := string(passwordByte)
password = strings.TrimSpace(password)
return &password
}
示例5: handleGetPass
// 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
}
示例6: readpass
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)
}
示例7: setPassword
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)
}
示例8: getPassphrase
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)
}
示例9: readNewPassword
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
}
示例10: main
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))
}
示例11: changePasswd
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")
}
示例12: verifyPasswd
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
}
示例13: main
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)
}
示例14: passwordFromReader
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
}
示例15: LoadCertificate
// 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,
}))
}