// KeyPairs Convert hashKey and blockKey to bytes
// @param hashKey
// @param blockKey
542440
func KeyPairs(keys ...string) [][]byte {
	var hashKey, blockKey string
	if len(keys) > 0 {
		hashKey = keys[0]
	}
	if len(keys) > 1 {
		blockKey = keys[1]
	}
	keyPairs := [][]byte{}
	if len(hashKey) > 0 {
		keyPairs = append(keyPairs, []byte(hashKey))

		if len(blockKey) > 0 && blockKey != hashKey {
			keyPairs = append(keyPairs, []byte(blockKey))
		}
	}
	return keyPairs
}
773923
func LoadKeypair(location string) (*ecdsa.PrivateKey, error) {
	priv, err := ioutil.ReadFile(filepath.Clean(location + "/server.key"))
	if err != nil {
		return nil, err
	}
	privBlock, _ := pem.Decode(priv)
	if privBlock == nil {
		return nil, errors.New("No private key data found")
	}
	privKey, err := x509.ParseECPrivateKey(privBlock.Bytes)
	if err != nil {
		return nil, err
	}
	return privKey, nil
}
1269256
func (l HostFirewallRulesetList) Keys() []string {
	var keys []string

	for _, rs := range l {
		keys = append(keys, rs.Key)
	}

	return keys
}
307312
func (e *Engine) GenerateKeypairs(ctx context.Context, notifier *observer.Notifier,
	OrgID *identity.ID) error {

	n := notifier.Notifier(4)

	kp, err := e.crypto.GenerateKeyPairs(ctx)
	if err != nil {
		log.Printf("Error generating keypairs: %s", err)
		return err
	}

	n.Notify(observer.Progress, "Keypairs generated", true)

	pubsig, privsig, err := packageSigningKeypair(ctx, e.crypto, e.session.AuthID(),
		OrgID, kp)
	if err != nil {
		log.Printf("Error packaging signing keypair: %s", err)
		return err
	}

	sigBody := primitive.NewClaim(OrgID, e.session.AuthID(), pubsig.ID, pubsig.ID,
		primitive.SignatureClaimType)
	sigclaim, err := e.crypto.SignedClaim(ctx, sigBody, pubsig.ID, &kp.Signature)
	if err != nil {
		log.Printf("Error creating signature claim: %s", err)
		return err
	}

	n.Notify(observer.Progress, "Signing keys signed", true)

	pubsig, privsig, claims, err := e.client.KeyPairs.Create(ctx, pubsig,
		privsig, sigclaim)
	if err != nil {
		log.Printf("Error uploading signature keypair: %s", err)
		return err
	}

	objs := make([]envelope.Envelope, len(claims)+2)
	objs[0] = pubsig
	objs[1] = privsig
	for i, claim := range claims {
		objs[i+2] = &claim
	}
	err = e.db.Set(objs...)
	if err != nil {
		log.Printf("Error storing signing keys in local db: %s", err)
		return err
	}

	n.Notify(observer.Progress, "Signing keys uploaded", true)

	pubenc, privenc, err := packageEncryptionKeypair(ctx, e.crypto, e.session.AuthID(),
		OrgID, kp, pubsig)
	if err != nil {
		log.Printf("Error packaging encryption keypair: %s", err)
	}

	encBody := primitive.NewClaim(OrgID, e.session.AuthID(), pubenc.ID, pubenc.ID,
		primitive.SignatureClaimType)
	encclaim, err := e.crypto.SignedClaim(ctx, encBody, pubsig.ID, &kp.Signature)
	if err != nil {
		log.Printf("Error creating signature claim for encryption key: %s", err)
		return err
	}

	n.Notify(observer.Progress, "Encryption keys signed", true)

	pubenc, privenc, claims, err = e.client.KeyPairs.Create(ctx, pubenc,
		privenc, encclaim)
	if err != nil {
		log.Printf("Error uploading encryption keypair: %s", err)
		return err
	}

	objs = make([]envelope.Envelope, len(claims)+2)
	objs[0] = pubenc
	objs[1] = privenc
	for i, claim := range claims {
		objs[i+2] = &claim
	}
	err = e.db.Set(objs...)
	if err != nil {
		log.Printf("Error storing encryption keys in local db: %s", err)
		return err
	}

	return nil
}
1034925
func headerKey(number uint64, hash common.Hash) []byte {
	return append(append(headerPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
}
1307452
func (whisper *Whisper) HasKeyPair(id string) bool {
	whisper.keyMu.RLock()
	defer whisper.keyMu.RUnlock()
	return whisper.privateKeys[id] != nil
}
686805
func newRsaKeyPair(config CreateKeyPairConfig) (KeyPair, error) {
	if config.Bits == 0 {
		config.Bits = defaultRsaBits
	}

	privateKey, err := rsa.GenerateKey(rand.Reader, config.Bits)
	if err != nil {
		return KeyPair{}, err
	}

	sshPublicKey, err := gossh.NewPublicKey(&privateKey.PublicKey)
	if err != nil {
		return KeyPair{}, err
	}

	privatePemBlock, err := rawPemBlock(&pem.Block{
		Type:    "RSA PRIVATE KEY",
		Headers: nil,
		Bytes:   x509.MarshalPKCS1PrivateKey(privateKey),
	})
	if err != nil {
		return KeyPair{}, err
	}

	return KeyPair{
		PrivateKeyPemBlock:          privatePemBlock,
		PublicKeyAuthorizedKeysLine: authorizedKeysLine(sshPublicKey, config.Comment),
		Comment:                     config.Comment,
	}, nil
}
116484
func GenerateKeyPair(passphrase string) ([]byte, []byte, error) {
	priv, err := rsa.GenerateKey(rand.Reader, teleport.RSAKeySize)
	if err != nil {
		return nil, nil, err
	}
	privDer := x509.MarshalPKCS1PrivateKey(priv)
	privBlock := pem.Block{
		Type:    "RSA PRIVATE KEY",
		Headers: nil,
		Bytes:   privDer,
	}
	privPem := pem.EncodeToMemory(&privBlock)

	pub, err := ssh.NewPublicKey(&priv.PublicKey)
	if err != nil {
		return nil, nil, err
	}
	pubBytes := ssh.MarshalAuthorizedKey(pub)
	return privPem, pubBytes, nil
}
1368367
func (client *Client) DetachKeyPair(args *DetachKeyPairArgs) (err error) {
	response := common.Response{}
	err = client.Invoke("DetachKeyPair", args, &response)
	if err != nil {
		return err
	}
	return nil
}
127621
func (m *clientConnMap) Keys() []string {
	m.RLock()

	res := make([]string, 0, len(m.conns))
	for k := range m.conns {
		res = append(res, k)
	}

	m.RUnlock()
	return res
}
810671
func (s *xorKeySpace) Key(id []byte) Key {
	hash := sha256.Sum256(id)
	key := hash[:]
	return Key{
		Space:    s,
		Original: id,
		Bytes:    key,
	}
}
1315024
func (vm *VM) SetKeyPair(privateKey string, name string) {
	vm.SSHCreds.SSHPrivateKey = privateKey
	vm.KeyPair = name
}
246340
func KeyPairFromPrivateKey(config FromPrivateKeyConfig) (KeyPair, error) {
	privateKey, err := gossh.ParseRawPrivateKey(config.RawPrivateKeyPemBlock)
	if err != nil {
		return KeyPair{}, err
	}

	switch pk := privateKey.(type) {
	case crypto.Signer:
		// crypto.Signer is implemented by ecdsa.PrivateKey,
		// ed25519.PrivateKey, and rsa.PrivateKey - separate cases
		// for each PrivateKey type would be redundant.
		publicKey, err := gossh.NewPublicKey(pk.Public())
		if err != nil {
			return KeyPair{}, err
		}
		return KeyPair{
			PrivateKeyPemBlock:          config.RawPrivateKeyPemBlock,
			PublicKeyAuthorizedKeysLine: authorizedKeysLine(publicKey, config.Comment),
		}, nil
	case *dsa.PrivateKey:
		publicKey, err := gossh.NewPublicKey(&pk.PublicKey)
		if err != nil {
			return KeyPair{}, err
		}
		return KeyPair{
			PrivateKeyPemBlock:          config.RawPrivateKeyPemBlock,
			PublicKeyAuthorizedKeysLine: authorizedKeysLine(publicKey, config.Comment),
		}, nil
	}

	return KeyPair{}, fmt.Errorf("Cannot parse existing SSH key pair - unknown key pair type")
}
1019155
func (m *SecureMap) Keys() []interface{} {
	m.lock.RLock()
	keys := make([]interface{}, len(m.data))
	count := 0
	for k := range m.data {
		keys[count] = k
		count++
	}
	m.lock.RUnlock()

	return keys
}
318877
func NewKeyPair() (keyPair *KeyPair, err error) {
	priv, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		return nil, ErrKeyGeneration
	}

	if err := priv.Validate(); err != nil {
		return nil, ErrValidation
	}

	privDer := x509.MarshalPKCS1PrivateKey(priv)
	privateKey := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Headers: nil, Bytes: privDer})
	pubSSH, err := gossh.NewPublicKey(&priv.PublicKey)
	if err != nil {
		return nil, ErrPublicKey
	}

	return &KeyPair{
		PrivateKey: privateKey,
		PublicKey:  gossh.MarshalAuthorizedKey(pubSSH),
	}, nil
}
1015642
func (s *CreateKeyPairOutput) SetKeyPair(v *KeyPair) *CreateKeyPairOutput {
	s.KeyPair = v
	return s
}
875015
func (s *InstanceAccessDetails) SetHostKeys(v []*HostKeyAttributes) *InstanceAccessDetails {
	s.HostKeys = v
	return s
}