func PrivateKeyFromString(data string) (*PrivKey, error) {
	if !strings.Contains(data, " ") {
		return nil, errIncorrectKeyFormat
	}

	// <type> <data>
	parts := strings.SplitN(data, " ", 2)
	if len(parts) != 2 {
		return nil, errIncorrectKeyFormat
	}

	pk := &PrivKey{}

	// Find the correct key type
	var err error
	pk.Type, err = FindKeyType(parts[0])
	if err != nil {
		return nil, errUnsupportedKeyType
	}

	// Set values
	pk.S = strings.TrimSpace(parts[1])
	pk.B = []byte(pk.S)

	// Decode base64 before we parse to key
	buf := make([]byte, base64.StdEncoding.DecodedLen(len(pk.B)))
	n, err := base64.StdEncoding.Decode(buf, pk.B)
	if err != nil {
		return nil, errIncorrectKeyFormat
	}

	// Parse key
	pk.K, err = pk.Type.ParsePrivateKeyData(buf[:n])

	if err != nil {
		return nil, errIncorrectKeyFormat
	}

	return pk, nil
}
// PrivateKeyFromString creates a new private key based on the string data "<type> <key>"
PrivateKeyFromString creates a new private key based on the string data " "
// PrivateKeyFromString creates a new private key based on the string data " <type > <key > "
func PrivateKeyFromString(data string) (*PrivKey, error) {
	if !strings.Contains(data, " ") {
		return nil, errIncorrectKeyFormat
	}
	parts := strings.SplitN(data, " ", 2)
	if len(parts) != 2 {
		return nil, errIncorrectKeyFormat
	}
	pk := &PrivKey{}
	var err error
	pk.Type, err = FindKeyType(parts[0])
	if err != nil {
		return nil, errUnsupportedKeyType
	}
	pk.S = strings.TrimSpace(parts[1])
	pk.B = []byte(pk.S)
	buf := make([]byte, base64.StdEncoding.DecodedLen(len(pk.B)))
	n, err := base64.StdEncoding.Decode(buf, pk.B)
	if err != nil {
		return nil, errIncorrectKeyFormat
	}
	pk.K, err = pk.Type.ParsePrivateKeyData(buf[:n])
	if err != nil {
		return nil, errIncorrectKeyFormat
	}
	return pk, nil
}
func PrivateKeyFromString ( data string ) ( * PrivKey , error ) { if ! strings . Contains ( data , " " ) { return nil , errIncorrectKeyFormat } parts := strings . SplitN ( data , " " , 2 ) if len ( parts ) != 2 { return nil , errIncorrectKeyFormat } pk := & PrivKey { } var err error pk . Type , err = FindKeyType ( parts [ 0 ] ) if err != nil { return nil , errUnsupportedKeyType } pk . S = strings . TrimSpace ( parts [ 1 ] ) pk . B = [ ] byte ( pk . S ) buf := make ( [ ] byte , base64 . StdEncoding . DecodedLen ( len ( pk . B ) ) ) n , err := base64 . StdEncoding . Decode ( buf , pk . B ) if err != nil { return nil , errIncorrectKeyFormat } pk . K , err = pk . Type . ParsePrivateKeyData ( buf [ : n ] ) if err != nil { return nil , errIncorrectKeyFormat } return pk , nil }
PrivateKeyFromString creates a new private key based on the string data " "
PrivateKeyFromString creates a new private key based on the string data " "
// <type> <data> // Find the correct key type // Set values // Decode base64 before we parse to key // Parse key