func UnmarshalPrivateKey(keyPEM, password string) (crypto.Signer, error) {
	block, rest := pem.Decode([]byte(keyPEM))
	if block == nil {
		return nil, errors.New("pemfile: invalid private key PEM")
	}
	if len(rest) > 0 {
		return nil, errors.New("pemfile: extra data found after first PEM block")
	}
	keyDER := block.Bytes
	if password != "" {
		pwdDer, err := x509.DecryptPEMBlock(block, []byte(password))  
		if err != nil {
			return nil, fmt.Errorf("pemfile: failed to decrypt: %v", err)
		}
		keyDER = pwdDer
	}
	return der.UnmarshalPrivateKey(keyDER)
}
UnmarshalPrivateKey reads a PEM-encoded private key from a string.
The key may be protected by a password.
package pem
import (
	"context"
	"crypto"
	"crypto/x509"
	"encoding/pem"
	"errors"
	"fmt"
	"io/ioutil"
	"github.com/google/trillian/crypto/keys/der"
	"github.com/google/trillian/crypto/keyspb"
	"google.golang.org/protobuf/proto"
)
func ReadPrivateKeyFile(file, password string) (crypto.Signer, error) {
	if password == "" {
		return nil, fmt.Errorf("pemfile: empty password for file %q", file)
	}
	keyPEM, err := ioutil.ReadFile(file)
	if err != nil {
		return nil, fmt.Errorf("pemfile: error reading file %q: %v", file, err)
	}
	k, err := UnmarshalPrivateKey(string(keyPEM), password)
	if err != nil {
		return nil, fmt.Errorf("pemfile: error decoding private key from file %q: %v", file, err)
	}
	return k, nil
}