func DecodePEMKey(key []byte) (*PrivateKey, error) {
	block, _ := pem.Decode(key)
	if block == nil {
		return nil, errors.New("key is not PEM encoded")
	}
	switch block.Type {
	case ECPrivateKey:
		k, err := x509.ParseECPrivateKey(block.Bytes)
		if err != nil {
			return nil, err
		}
		return &PrivateKey{Type: ECPrivateKey, Key: k}, nil
	case RSAPrivateKey:
		k, err := x509.ParsePKCS1PrivateKey(block.Bytes)
		if err != nil {
			return nil, err
		}
		return &PrivateKey{Type: RSAPrivateKey, Key: k}, nil
	case PKCS8PrivateKey:
		k, err := x509.ParsePKCS8PrivateKey(block.Bytes)
		if err != nil {
			return nil, err
		}
		return &PrivateKey{Type: PKCS8PrivateKey, Key: k}, nil
	default:
		return nil, errors.Errorf("unsupported block type %s", block.Type)
	}
}
DecodePEMKey takes a key PEM byte array and returns a PrivateKey that represents
Either an RSA or EC private key.
package certs
import (
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	"crypto/rsa"
	"crypto/x509"
	"encoding/pem"
	"github.com/pkg/errors"
)
const (
	Certificate     = "CERTIFICATE"
	ECPrivateKey    = "EC PRIVATE KEY"
	RSAPrivateKey   = "RSA PRIVATE KEY"
	PKCS8PrivateKey = "PRIVATE KEY"
)
type PrivateKey struct {
	Type string
	Key  interface{}
}
type Credentials struct {
	PrivateKey  *PrivateKey
	Certificate *x509.Certificate
}