當前位置: 首頁>>代碼示例>>Golang>>正文


Golang scrypt.Key函數代碼示例

本文整理匯總了Golang中code/google/com/p/go/crypto/scrypt.Key函數的典型用法代碼示例。如果您正苦於以下問題:Golang Key函數的具體用法?Golang Key怎麽用?Golang Key使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Key函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Reconnect

func (c *Client) Reconnect() error {
	conn, err := tls.Dial("tcp", c.hostname, c.config)
	if err != nil {
		return err
	}
	c.conn = conn

	loginByte := []byte{TReconnect}
	c.conn.Write(loginByte)
	ulen := WriteInt32(int32(len(c.username)))
	c.conn.Write(ulen)
	c.conn.Write([]byte(c.username))
	sc := make([]byte, 32)
	c.conn.Read(sc)

	//Generate a response
	cc := GeneratePepper()
	combSalt := make([]byte, len(sc)+len(cc))
	copy(combSalt, sc)
	copy(combSalt[len(sc):], cc)

	//Generate a hash of the password with the challenge and response as salts
	hashA, _ := scrypt.Key(c.phash, combSalt, 16384, 8, 1, 32)

	//write the hash, and the response
	c.conn.Write(hashA)
	c.conn.Write(cc)
	sr := make([]byte, 32)

	//Read the servers response
	_, err = c.conn.Read(sr)
	if err != nil {
		return err
	}
	srVer, _ := scrypt.Key(c.phash, combSalt, 16384, 4, 3, 32)

	//and ensure that it is correct
	for i := 0; i < 32; i++ {
		if sr[i] != srVer[i] {
			return errors.New("Invalid response from server")
		}
	}
	//Send login flags to the server
	loginByte[0] = c.lflags
	c.conn.Write(loginByte)

	return nil
}
開發者ID:nnoco,項目名稱:GoLiathChat,代碼行數:48,代碼來源:Client.go

示例2: deriveKey

func deriveKey(result chan []byte, secret string) {
	keySlice, err := scrypt.Key([]byte(secret), nil, 1<<18, 20, 1, 32)
	if err != nil {
		panic(err)
	}
	result <- keySlice
}
開發者ID:ioerror,項目名稱:panda,代碼行數:7,代碼來源:client.go

示例3: HashPassword

func HashPassword(username, password string) []byte {
	pHash, err := scrypt.Key([]byte(password), []byte(tSalt+username), 16384, 9, 7, 32)
	if err != nil {
		panic(err)
	}
	return pHash
}
開發者ID:nnoco,項目名稱:GoLiathChat,代碼行數:7,代碼來源:Tools.go

示例4: CheckPassword

func (u *User) CheckPassword(password string) bool {
	passwordHash, err := scrypt.Key([]byte(password), u.PasswordSalt, 16384, 8, 1, 32)
	if err != nil {
		panic(err)
	}
	return subtle.ConstantTimeCompare(passwordHash, u.PasswordHash) == 1
}
開發者ID:pombredanne,項目名稱:inventory,代碼行數:7,代碼來源:model.go

示例5: HashPassword

func (a *AccountDetail) HashPassword(password string) []byte {
	hash, err := scrypt.Key([]byte(password), a.Salt, a.N, a.R, a.P, 32)
	if err != nil {
		panic(err)
	}
	return hash
}
開發者ID:nulpunt,項目名稱:nulpunt,代碼行數:7,代碼來源:account.go

示例6: initLazyKey

func (e *EmailAddr) initLazyKey() {
	emailKey := e.Canonical()
	keyCache.Lock()
	v, ok := keyCache.m[emailKey]
	keyCache.Unlock()

	if ok {
		e.lazyKey = v
		return
	}

	key, err := scrypt.Key([]byte(emailKey), fistSalt, 16384*8, 8, 1, 32)
	if err != nil {
		panic(err)
	}
	e.lazyKey = key

	keyCache.Lock()
	if keyCache.m == nil {
		keyCache.m = make(map[string][]byte)
	}
	keyCache.m[emailKey] = key
	// TODO: Prune the cache
	keyCache.Unlock()
}
開發者ID:jaredhanson,項目名稱:webfist,代碼行數:25,代碼來源:addr.go

示例7: Login

// Handles login functions, returns true (successful) false (unsucessful)
func (h *Client) Login(handle, password string, lflags byte) (bool, string) {
	loginByte := make([]byte, 1)
	loginByte[0] = TLogin
	h.conn.Write(loginByte)
	h.phash = HashPassword(handle, password)
	//Write the usernames length, followed by the username.
	ulen := WriteInt32(int32(len(handle)))
	h.conn.Write(ulen)
	h.conn.Write([]byte(handle))
	h.username = handle
	//Read the servers challenge
	sc := make([]byte, 32)
	h.conn.Read(sc)

	//Generate a response
	cc := GeneratePepper()
	combSalt := make([]byte, len(sc)+len(cc))
	copy(combSalt, sc)
	copy(combSalt[len(sc):], cc)

	//Generate a hash of the password with the challenge and response as salts
	hashA, _ := scrypt.Key(h.phash, combSalt, 16384, 8, 1, 32)

	//write the hash, and the response
	h.conn.Write(hashA)
	h.conn.Write(cc)
	sr := make([]byte, 32)

	//Read the servers response
	_, err := h.conn.Read(sr)
	if err != nil {
		return false, "Auth Failed."
	}
	srVer, _ := scrypt.Key(h.phash, combSalt, 16384, 4, 3, 32)

	//and ensure that it is correct
	for i := 0; i < 32; i++ {
		if sr[i] != srVer[i] {
			return false, "Invalid response from server"
		}
	}
	//Send login flags to the server
	loginByte[0] = lflags
	h.conn.Write(loginByte)

	return true, "Authenticated"
}
開發者ID:nnoco,項目名稱:GoLiathChat,代碼行數:48,代碼來源:Client.go

示例8: main

func main() {
	stateFile := flag.String("state-file", "", "File in which to save persistent state")
	pandaScrypt := flag.Bool("panda-scrypt", false, "Run in subprocess mode to process passphrase")
	cliFlag := flag.Bool("cli", false, "If true, the CLI will be used, even if the GUI is available")
	devFlag := flag.Bool("dev", false, "Is this a development environment?")
	flag.Parse()

	if *pandaScrypt {
		var numBytes uint32
		if err := binary.Read(os.Stdin, binary.LittleEndian, &numBytes); err != nil {
			panic(err)
		}
		if numBytes > 1024*1024 {
			panic("passphrase too large")
		}
		passphrase := make([]byte, int(numBytes))
		if _, err := os.Stdin.Read(passphrase); err != nil {
			panic(err)
		}
		data, err := scrypt.Key(passphrase, nil, 1<<17, 16, 4, 32*3)
		if err != nil {
			panic(err)
		}
		os.Stdout.Write(data)
		os.Exit(0)
	}

	dev := os.Getenv("POND") == "dev" || *devFlag
	runtime.GOMAXPROCS(4)

	if len(*stateFile) == 0 && dev {
		*stateFile = "state"
	}

	if len(*stateFile) == 0 {
		home := os.Getenv("HOME")
		if len(home) == 0 {
			fmt.Fprintf(os.Stderr, "$HOME not set. Please either export $HOME or use --state-file to set the location of the state file explicitly.\n")
			os.Exit(1)
		}
		configDir := filepath.Join(home, ".config")
		os.Mkdir(configDir, 0700)
		*stateFile = filepath.Join(configDir, "pond")
	}

	if !haveGUI || *cliFlag || len(os.Getenv("PONDCLI")) > 0 {
		client := NewCLIClient(*stateFile, rand.Reader, false /* testing */, true /* autoFetch */)
		client.disableV2Ratchet = true
		client.dev = dev
		client.Start()
	} else {
		ui := NewGTKUI()
		client := NewGUIClient(*stateFile, ui, rand.Reader, false /* testing */, true /* autoFetch */)
		client.disableV2Ratchet = true
		client.dev = dev
		client.Start()
		ui.Run()
	}
}
開發者ID:houndbee,項目名稱:pond,代碼行數:59,代碼來源:main_linux.go

示例9: Authenticate

func (user *User) Authenticate(password string) bool {
	// Scrypt the password.
	scryptPassword, err := scrypt.Key([]byte(password), user.Salt, 16384, 8, 1, 32)
	if err != nil {
		panic(err)
	}
	return bytes.Equal(scryptPassword, user.Scrypt)
}
開發者ID:jaekwon,項目名稱:ftnox-backend,代碼行數:8,代碼來源:models.go

示例10: BenchmarkR32768r8p4k32

func BenchmarkR32768r8p4k32(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, err := scrypt.Key(password, salt, 32768, 8, 4, 32)
		if err != nil {
			b.Fatalf("%v", err)
		}
	}
}
開發者ID:kisom,項目名稱:gosf201407,代碼行數:8,代碼來源:scrypt_test.go

示例11: BenchmarkR16384r8p1k32

func BenchmarkR16384r8p1k32(b *testing.B) {
	for i := 0; i < b.N; i++ {
		_, err := scrypt.Key(password, salt, 16384, 8, 1, 32)
		if err != nil {
			b.Fatalf("%v", err)
		}
	}
}
開發者ID:kisom,項目名稱:gosf201407,代碼行數:8,代碼來源:scrypt_test.go

示例12: scryptHash

func (p *adminPlugin) scryptHash(cmd *mup.Command, password, salt string) (hash string, ok bool) {
	key, err := scrypt.Key([]byte(password), []byte(salt), 16384, 8, 1, 32)
	if err != nil {
		p.plugger.Logf("scrypt.Key failed: %v", err)
		p.plugger.Sendf(cmd, "Internal error hashing password. Sorry.")
	}
	return hex.EncodeToString(key), err == nil
}
開發者ID:jmptrader,項目名稱:mup,代碼行數:8,代碼來源:admin.go

示例13: deriveScrypt

func deriveScrypt(in [32]byte) (psk [32]byte, err error) {
	out, err := scrypt.Key(in[:], in[:], 1<<16, 8, 1, 32)
	if err != nil {
		return
	}
	copy(psk[:], out)

	return
}
開發者ID:rakoo,項目名稱:rakoshare,代碼行數:9,代碼來源:id.go

示例14: recoverKey

func recoverKey(password, salt []byte) (key []byte, ok bool) {
	key, err := scrypt.Key(password, salt, scryN, scryP, scryR, pwKeyLength)
	if err != nil {
		key = nil
		salt = nil
		return
	}
	ok = true
	return
}
開發者ID:postfix,項目名稱:cryptobox-ng,代碼行數:10,代碼來源:passwordbox.go

示例15: deriveKey

// deriveKey applies Scrypt with very strong parameters to generate an
// encryption key from a passphrase and salt.
func deriveKey(passphrase []byte, salt []byte) *[keySize]byte {
	rawKey, err := scrypt.Key(passphrase, salt, 32768, 8, 4, keySize)
	if err != nil {
		return nil
	}

	var key [keySize]byte
	copy(key[:], rawKey)
	zero(rawKey)
	return &key
}
開發者ID:kisom,項目名稱:password,代碼行數:13,代碼來源:crypto.go


注:本文中的code/google/com/p/go/crypto/scrypt.Key函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。