func (o *Command) ImportKey(rw io.Writer, req io.Reader) command.Error {
	buf := new(bytes.Buffer)
	_, err := buf.ReadFrom(req)
	if err != nil {
		logutil.LogInfo(logger, CommandName, ImportKeyCommandMethod, err.Error())
		return command.NewValidationError(InvalidRequestErrorCode, fmt.Errorf("failed request decode : %w", err))
	}
	var j jwk.JWK
	if errUnmarshal := j.UnmarshalJSON(buf.Bytes()); errUnmarshal != nil {
		logutil.LogInfo(logger, CommandName, ImportKeyCommandMethod, errUnmarshal.Error())
		return command.NewValidationError(InvalidRequestErrorCode, fmt.Errorf("failed request decode : %w", err))
	}
	if j.KeyID == "" {
		logutil.LogDebug(logger, CommandName, ImportKeyCommandMethod, errEmptyKeyID)
		return command.NewValidationError(InvalidRequestErrorCode, fmt.Errorf(errEmptyKeyID))
	}
	var keyType kms.KeyType
	switch j.Crv {
	case "Ed25519":
		keyType = kms.ED25519Type
	case "P-256":
		keyType = kms.ECDSAP256TypeIEEEP1363
	case "BLS12381_G2":
		keyType = kms.BLS12381G2Type
	default:
		return command.NewValidationError(InvalidRequestErrorCode,
			fmt.Errorf("import key type not supported %s", j.Crv))
	}
	_, _, err = o.importKey(j.Key, keyType, kms.WithKeyID(j.KeyID))
	if err != nil {
		logutil.LogError(logger, CommandName, ImportKeyCommandMethod, err.Error())
		return command.NewExecuteError(ImportKeyError, err)
	}
	command.WriteNillableResponse(rw, nil, logger)
	logutil.LogDebug(logger, CommandName, ImportKeyCommandMethod, "success")
	return nil
}
ImportKey import key.
package kms
import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io"
	"github.com/hyperledger/aries-framework-go/pkg/common/log"
	"github.com/hyperledger/aries-framework-go/pkg/controller/command"
	"github.com/hyperledger/aries-framework-go/pkg/controller/internal/cmdutil"
	"github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk"
	"github.com/hyperledger/aries-framework-go/pkg/internal/logutil"
	"github.com/hyperledger/aries-framework-go/pkg/kms"
)
var logger = log.New("aries-framework/command/kms")
const (
	InvalidRequestErrorCode = command.Code(iota + command.KMS)
	CreateKeySetError
	ImportKeyError
)
const (
	CommandName = "kms"
	CreateKeySetCommandMethod = "CreateKeySet"
	ImportKeyCommandMethod    = "ImportKey"
	errEmptyKeyType = "key type is mandatory"
	errEmptyKeyID   = "key id is mandatory"
)
type provider interface {
	KMS() kms.KeyManager
}
type Command struct {
	ctx       provider
	importKey func(privKey interface{}, kt kms.KeyType,
		opts ...kms.PrivateKeyOpts) (string, interface{}, error)  
}
func New(p provider) *Command {
	return &Command{
		ctx: p,
		importKey: func(privKey interface{}, kt kms.KeyType,
			opts ...kms.PrivateKeyOpts) (string, interface{}, error) {
			return p.KMS().ImportPrivateKey(privKey, kt, opts...)
		},
	}
}
func (o *Command) GetHandlers() []command.Handler {
	return []command.Handler{
		cmdutil.NewCommandHandler(CommandName, CreateKeySetCommandMethod, o.CreateKeySet),
		cmdutil.NewCommandHandler(CommandName, ImportKeyCommandMethod, o.ImportKey),
	}
}
func (o *Command) CreateKeySet(rw io.Writer, req io.Reader) command.Error {
	var request CreateKeySetRequest
	err := json.NewDecoder(req).Decode(&request)
	if err != nil {
		logutil.LogInfo(logger, CommandName, CreateKeySetCommandMethod, err.Error())
		return command.NewValidationError(InvalidRequestErrorCode, fmt.Errorf("failed request decode : %w", err))
	}
	if request.KeyType == "" {
		logutil.LogDebug(logger, CommandName, CreateKeySetCommandMethod, errEmptyKeyType)
		return command.NewValidationError(InvalidRequestErrorCode, fmt.Errorf(errEmptyKeyType))
	}
	keyID, pubKeyBytes, err := o.ctx.KMS().CreateAndExportPubKeyBytes(kms.KeyType(request.KeyType))
	if err != nil {
		logutil.LogError(logger, CommandName, CreateKeySetCommandMethod, err.Error())
		return command.NewExecuteError(CreateKeySetError, err)
	}
	command.WriteNillableResponse(rw, &CreateKeySetResponse{
		KeyID:     keyID,
		PublicKey: base64.RawURLEncoding.EncodeToString(pubKeyBytes),
	}, logger)
	logutil.LogDebug(logger, CommandName, CreateKeySetCommandMethod, "success")
	return nil
}