// Returns key from keypath or uses salt + passphrase to generate key using a KDF.
14756
func generateKey(keypath string, salt []byte, keyiter int) (key *[secret.SecretKeyLength]byte, isPass bool, err error) {
	// if a keypath is given try and use it
	if keypath != "" {
		key, err := secret.ReadKeyFromDisk(keypath)
		if err != nil {
			return nil, false, fmt.Errorf("unable to build secret service: %v", err)
		}
		return key, false, nil
	}

	// otherwise read in a passphrase from disk and use that, remember to reset your terminal afterwards
	var passphrase string
	fmt.Printf("Passphrase: ")
	fmt.Scanln(&passphrase)

	// derive key and return it
	keySlice := pbkdf2.Key([]byte(passphrase), salt, keyiter, 32, sha256.New)
	keyBytes, err := secret.KeySliceToArray(keySlice)
	if err != nil {
		return nil, true, err
	}

	return keyBytes, true, nil
}
1175700
func (g *PrefixKeyGenerator) GetKey(params imageserver.Params) string {
	return g.Prefix + g.KeyGenerator.GetKey(params)
}
1069665
func (cs *CryptoService) GetPrivateKey(keyID string) (k data.PrivateKey, role data.RoleName, err error) {
	for _, ks := range cs.keyStores {
		if k, role, err = ks.GetKey(keyID); err == nil {
			return
		}
		switch err.(type) {
		case trustmanager.ErrPasswordInvalid, trustmanager.ErrAttemptsExceeded:
			return
		default:
			continue
		}
	}
	return // returns whatever the final values were
}
618644
func (f *FileStore) getPathByKey(key string) string {
	return filepath.Join(f.directoryPath, key)
}
107370
func (v *RPC) GetShardKey() (o string) {
	if v != nil && v.ShardKey != nil {
		return *v.ShardKey
	}

	return
}
933086
func (trust *NotarySigner) GetPrivateKey(keyid string) (data.PrivateKey, data.RoleName, error) {
	pubKey, role, err := trust.getKeyInfo(keyid)
	if err != nil {
		return nil, "", err
	}
	return NewRemotePrivateKey(pubKey, trust.sClient), role, nil
}
553363
func (k *KeyFinderImpl) FindForDecryption(ctx context.Context,
	tlfName string, tlfID chat1.TLFID,
	membersType chat1.ConversationMembersType, public bool,
	keyGeneration int, kbfsEncrypted bool) (res types.CryptKey, err error) {
	ckey := k.decCacheKey(tlfName, tlfID, membersType, keyGeneration, public, kbfsEncrypted)
	existing, ok := k.lookupDecKey(ckey)
	if ok {
		return existing, nil
	}
	defer func() {
		if err == nil {
			k.writeDecKey(ckey, res)
		}
	}()
	return k.createNameInfoSource(ctx, membersType).DecryptionKey(ctx, tlfName, tlfID,
		membersType, public, keyGeneration, kbfsEncrypted)
}
818702
func (s *SharedStore) keyPath(key NamedKey) string {
	// WARNING - STABLE API: The composition of the absolute key path
	// cannot be changed without breaking up and downgrades.
	return path.Join(s.conf.Prefix, key.GetKeyName())
}
1118330
func PBKDF2(password, salt []byte, iter, keylen int, hashFunc crypto.Hash) ([]byte, error) {
	h, ok := hashFuncs[hashFunc]
	if !ok {
		return nil, errors.Errorf("hashFunc not supported: %v", hashFunc)
	}
	return pbkdf2.Key(password, salt, iter, keylen, h), nil
}
807458
func (s *Key) Path() string {
	return fmt.Sprintf("%s/%s", s.P, s.N)
}
511293
func (b *Backend) Get(ctx context.Context, key string) ([]byte, error) {
	var err error

	if b.secret == nil {
		b.secret, err = b.client.Read(b.path)
		if err != nil {
			return nil, err
		}

		if b.secret == nil {
			return nil, fmt.Errorf("secret not found at the following path: %s", b.path)
		}
	}

	if v, ok := b.secret.Data[key]; ok {
		return []byte(v.(string)), nil
	}

	return nil, backend.ErrNotFound
}
863943
func writeKey(keyDir string, addr, keyJson []byte) ([]byte, error) {
	dir, err := returnDataDir(keyDir)
	if err != nil {
		return nil, fmt.Errorf("Failed to get keys dir: %v", err)
	}
	if err := WriteKeyFile(addr, dir, keyJson); err != nil {
		return nil, err
	}
	return addr, nil
}
978322
func (k *Key) GetKey() string {
	if k == nil || k.Key == nil {
		return ""
	}
	return *k.Key
}
293675
func (c *Client) GenerateKeyPair(pass string) ([]byte, []byte, error) {
	out, err := c.PostJSON(c.Endpoint("keypair"), generateKeyPairReq{Password: pass})
	if err != nil {
		return nil, nil, trace.Wrap(err)
	}
	var kp *generateKeyPairResponse
	if err := json.Unmarshal(out.Bytes(), &kp); err != nil {
		return nil, nil, err
	}
	return kp.PrivKey, []byte(kp.PubKey), err
}
143657
func (trust *NotarySigner) GetKey(keyid string) data.PublicKey {
	pubKey, _, err := trust.getKeyInfo(keyid)
	if err != nil {
		return nil
	}
	return pubKey
}
386164
func (v *KeyValue_SetValue_Args) GetKey() (o string) {
	if v != nil && v.Key != nil {
		return *v.Key
	}

	return
}
271024
func (k Key) Path() Key {
	s := k.Parent().string + "/" + NamespaceType(k.BaseNamespace())
	return NewKey(s)
}