libmachine/ssh/keys.go
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)

	pubSSH, err := gossh.NewPublicKey(&priv.PublicKey)
	if err != nil {
		return nil, ErrPublicKey
	}

	return &KeyPair{
		PrivateKey: privDer,
		PublicKey:  gossh.MarshalAuthorizedKey(pubSSH),
	}, nil
}
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)

	pubSSH, err := gossh.NewPublicKey(&priv.PublicKey)
	if err != nil {
		return nil, ErrPublicKey
	}

	return &KeyPair{
		PrivateKey: privDer,
		PublicKey:  gossh.MarshalAuthorizedKey(pubSSH),
	}, nil
}
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 ) pubSSH , err := gossh . NewPublicKey ( & priv . PublicKey ) if err != nil { return nil , ErrPublicKey } return & KeyPair { PrivateKey : privDer , PublicKey : gossh . MarshalAuthorizedKey ( pubSSH ) , } , nil }
// NewKeyPair generates a new SSH keypair
// This will return a private & public key encoded as DER.
NewKeyPair generates a new SSH keypair This will return a private & public key encoded as DER .