

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# AWS KMS ECDH 키링
<a name="use-kms-ecdh-keyring"></a>

 AWS KMS ECDH 키링은 비대칭 키 계약을 사용하여 두 당사자 간에 공유 대칭 래핑 키를 [AWS KMS keys](https://docs.aws.amazon.com/kms/latest/developerguide/key-types.html) 도출합니다. 먼저 키링은 Elliptic Curve Diffie-Hellman(ECDH) 키 계약 알고리즘을 사용하여 발신자의 KMS 키 페어와 수신자의 퍼블릭 키에 있는 프라이빗 키에서 공유 암호를 도출합니다. 그런 다음 키링은 공유 보안 암호를 사용하여 데이터 암호화 키를 보호하는 공유 래핑 키를 파생합니다. 가 (`KDF_CTR_HMAC_SHA384`)를 AWS Encryption SDK 사용하여 공유 래핑 키를 파생하는 키 파생 함수는 [키 파생에 대한 NIST 권장 사항을](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-108r1-upd1.pdf) 준수합니다.

키 파생 함수는 64바이트의 키 지정 구성 요소를 반환합니다. 양 당사자가 올바른 키 구성 요소를 사용하도록 하기 위해는 처음 32바이트를 커밋 키로 사용하고 마지막 32바이트를 공유 래핑 키로 AWS Encryption SDK 사용합니다. 복호화 시 키링이 메시지 헤더 사이퍼텍스트에 저장된 동일한 커밋 키와 공유 래핑 키를 재현할 수 없는 경우 작업이 실패합니다. 예를 들어 **Alice의** 프라이빗 키와 **Bob의** 퍼블릭 키로 구성된 키링으로 데이터를 암호화하는 경우 **Bob의** 프라이빗 키와 **Alice의** 퍼블릭 키로 구성된 키링은 동일한 커밋 키와 공유 래핑 키를 재현하고 데이터를 해독할 수 있습니다. Bob의 퍼블릭 키가 KMS 키 페어가 아닌 경우 Bob은 [원시 ECDH 키링](use-raw-ecdh-keyring.md)을 생성하여 데이터를 해독할 수 있습니다.

 AWS KMS ECDH 키링은 AES-GCM을 사용하여 대칭 키로 데이터를 암호화합니다. 그런 다음 AES-GCM을 사용하여 파생된 공유 래핑 키로 데이터 키를 봉투 암호화합니다. 각 AWS KMS ECDH 키링에는 공유 래핑 키가 하나만 있을 수 있지만, 다중 키링에는 단독으로 또는 다른 키링과 함께 여러 AWS KMS ECDH 키[링](use-multi-keyring.md)을 포함할 수 있습니다.

**프로그래밍 언어 호환성**  
 AWS KMS ECDH 키링은 [암호화 자료 공급자 라이브러리](https://github.com/aws/aws-cryptographic-material-providers-library)(MPL) 버전 1.5.0에 도입되었으며 다음 프로그래밍 언어 및 버전에서 지원됩니다.
+ 의 버전 3.*x* AWS Encryption SDK for Java
+ for .NET 버전 AWS Encryption SDK 4.*x* 이상
+ 선택적 MPL 종속성과 함께 사용하는 AWS Encryption SDK for Python경우 버전 4.*x*.
+  AWS Encryption SDK for Rust 버전 1.*x* 
+ Go AWS Encryption SDK 용의 버전 0.1.*x* 이상

**Topics**
+ [AWS KMS ECDH 키링에 필요한 권한](#kms-ecdh-permissions)
+ [AWS KMS ECDH 키링 생성](#kms-ecdh-create)
+ [AWS KMS ECDH 검색 키링 생성](#kms-ecdh-discovery)

## AWS KMS ECDH 키링에 필요한 권한
<a name="kms-ecdh-permissions"></a>

 AWS Encryption SDK 에는 AWS 계정이 필요하지 않으며 서비스에 AWS 의존하지 않습니다. 그러나 AWS KMS ECDH 키링을 사용하려면 키링의 AWS KMS keys 에 대한 AWS 계정과 다음과 같은 최소 권한이 필요합니다. 권한은 사용하는 키 계약 스키마에 따라 달라집니다.
+ `KmsPrivateKeyToStaticPublicKey` 키 계약 스키마를 사용하여 데이터를 암호화하고 해독하려면 *발신자의* 비대칭 KMS 키 페어에 [kms:GetPublicKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GetPublicKey.html) 및 [kms:DeriveSharedSecret](https://docs.aws.amazon.com/kms/latest/APIReference/API_DeriveSharedSecret.html)이 필요합니다. 키링을 인스턴스화할 때 발신자의 DER 인코딩 퍼블릭 키를 직접 제공하는 경우 발신자의 비대칭 KMS 키 페어에 대한 [kms:DeriveSharedSecret](https://docs.aws.amazon.com/kms/latest/APIReference/API_DeriveSharedSecret.html) 권한만 있으면 됩니다.
+ `KmsPublicKeyDiscovery` 키 계약 스키마를 사용하여 데이터를 복호화하려면 지정된 비대칭 KMS 키 페어에 대한 [kms:DeriveSharedSecret](https://docs.aws.amazon.com/kms/latest/APIReference/API_DeriveSharedSecret.html) 및 [kms:GetPublicKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GetPublicKey.html) 권한이 필요합니다.

## AWS KMS ECDH 키링 생성
<a name="kms-ecdh-create"></a>

데이터를 암호화하고 해독하는 AWS KMS ECDH 키링을 생성하려면 `KmsPrivateKeyToStaticPublicKey` 키 계약 스키마를 사용해야 합니다. `KmsPrivateKeyToStaticPublicKey` 키 계약 스키마를 사용하여 AWS KMS ECDH 키링을 초기화하려면 다음 값을 제공합니다.
+ **발신자 AWS KMS key ID**

  `KeyUsage` 값이 인 비대칭 NIST 권장 타원 곡선(ECC) KMS 키 페어를 식별해야 합니다`KEY_AGREEMENT`. 발신자의 프라이빗 키는 공유 암호를 도출하는 데 사용됩니다.
+ **(선택 사항) 발신자의 퍼블릭 키**

  RFC 5280에 정의된 대로 `SubjectPublicKeyInfo` (SPKI)라고도 하는 DER 인코딩 X.509 퍼블릭 키여야 합니다. [https://tools.ietf.org/html/rfc5280](https://tools.ietf.org/html/rfc5280) 

   AWS KMS [GetPublicKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GetPublicKey.html) 작업은 비대칭 KMS 키 페어의 퍼블릭 키를 필요한 DER 인코딩 형식으로 반환합니다.

  키링이 수행하는 AWS KMS 호출 수를 줄이기 위해 발신자의 퍼블릭 키를 직접 제공할 수 있습니다. 발신자의 퍼블릭 키에 값이 제공되지 않은 경우 키링은를 호출 AWS KMS 하여 발신자의 퍼블릭 키를 검색합니다.
+ **수신자의 퍼블릭 키**

  RFC 5280에 정의된 대로 `SubjectPublicKeyInfo` (SPKI)라고도 하는 수신자의 DER 인코딩 X.509 퍼블릭 키를 제공해야 합니다. [https://tools.ietf.org/html/rfc5280](https://tools.ietf.org/html/rfc5280) 

   AWS KMS [GetPublicKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GetPublicKey.html) 작업은 비대칭 KMS 키 페어의 퍼블릭 키를 필요한 DER 인코딩 형식으로 반환합니다.
+ **곡선 사양**

  지정된 키 페어에서 타원 곡선 사양을 식별합니다. 발신자와 수신자의 키 페어 모두 곡선 사양이 동일해야 합니다.

  유효한 값: `ECC_NIST_P256`, `ECC_NIS_P384`, `ECC_NIST_P512` 
+ **(선택 사항) 권한 부여 토큰 목록**

  [권한 부여](https://docs.aws.amazon.com/kms/latest/developerguide/grants.html)를 사용하여 AWS KMS ECDH 키링의 KMS 키에 대한 액세스를 제어하는 경우 키링을 초기화할 때 필요한 모든 권한 부여 토큰을 제공해야 합니다.

------
#### [ C\$1 / .NET ]

다음 예제에서는 발신자의 KMS 키, 발신자의 퍼블릭 키 및 수신자의 퍼블릭 키를 사용하여 AWS KMS 로 ECDH 키링을 생성합니다. 이 예제에서는 선택적 `SenderPublicKey` 파라미터를 사용하여 발신자의 퍼블릭 키를 제공합니다. 발신자의 퍼블릭 키를 제공하지 않으면 키링이를 호출 AWS KMS 하여 발신자의 퍼블릭 키를 검색합니다. 발신자와 수신자의 키 페어가 모두 `ECC_NIST_P256` 곡선에 있습니다.

```
// Instantiate material providers
var materialProviders = new MaterialProviders(new MaterialProvidersConfig());

// Must be DER-encoded X.509 public keys
var BobPublicKey = new MemoryStream(new byte[] { });
var AlicePublicKey = new MemoryStream(new byte[] { });

// Create the AWS KMS ECDH static keyring
var staticConfiguration = new KmsEcdhStaticConfigurations
{
    KmsPrivateKeyToStaticPublicKey = new KmsPrivateKeyToStaticPublicKeyInput
    {
        SenderKmsIdentifier = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
        SenderPublicKey = BobPublicKey,
        RecipientPublicKey = AlicePublicKey
    }
};
	    
var createKeyringInput = new CreateAwsKmsEcdhKeyringInput
{
    CurveSpec = ECDHCurveSpec.ECC_NIST_P256,
    KmsClient = new AmazonKeyManagementServiceClient(),
    KeyAgreementScheme = staticConfiguration
};

var keyring = materialProviders.CreateAwsKmsEcdhKeyring(createKeyringInput);
```

------
#### [ Java ]

다음 예제에서는 발신자의 KMS 키, 발신자의 퍼블릭 키 및 수신자의 퍼블릭 키를 사용하여 AWS KMS 로 ECDH 키링을 생성합니다. 이 예제에서는 선택적 `senderPublicKey` 파라미터를 사용하여 발신자의 퍼블릭 키를 제공합니다. 발신자의 퍼블릭 키를 제공하지 않으면 키링이를 호출 AWS KMS 하여 발신자의 퍼블릭 키를 검색합니다. 발신자와 수신자의 키 페어가 모두 `ECC_NIST_P256` 곡선에 있습니다.

```
// Retrieve public keys
// Must be DER-encoded X.509 public keys                                
ByteBuffer BobPublicKey = getPublicKeyBytes("arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab");
        ByteBuffer AlicePublicKey = getPublicKeyBytes("arn:aws:kms:us-west-2:111122223333:key/0987dcba-09fe-87dc-65ba-ab0987654321"); 

// Create the AWS KMS ECDH static keyring
        final CreateAwsKmsEcdhKeyringInput senderKeyringInput =
          CreateAwsKmsEcdhKeyringInput.builder()
            .kmsClient(KmsClient.create())
            .curveSpec(ECDHCurveSpec.ECC_NIST_P256)
            .KeyAgreementScheme(
              KmsEcdhStaticConfigurations.builder()
                .KmsPrivateKeyToStaticPublicKey(
                  KmsPrivateKeyToStaticPublicKeyInput.builder()
                    .senderKmsIdentifier("arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab")
                    .senderPublicKey(BobPublicKey)
                    .recipientPublicKey(AlicePublicKey)
                    .build()).build()).build();
```

------
#### [ Python ]

다음 예제에서는 발신자의 KMS 키, 발신자의 퍼블릭 키 및 수신자의 퍼블릭 키를 사용하여 AWS KMS 로 ECDH 키링을 생성합니다. 이 예제에서는 선택적 `senderPublicKey` 파라미터를 사용하여 발신자의 퍼블릭 키를 제공합니다. 발신자의 퍼블릭 키를 제공하지 않으면 키링이를 호출 AWS KMS 하여 발신자의 퍼블릭 키를 검색합니다. 발신자와 수신자의 키 페어가 모두 `ECC_NIST_P256` 곡선에 있습니다.

```
import boto3
from aws_cryptographic_materialproviders.mpl.models import (
    CreateAwsKmsEcdhKeyringInput,
    KmsEcdhStaticConfigurationsKmsPrivateKeyToStaticPublicKey,
    KmsPrivateKeyToStaticPublicKeyInput,
)
from aws_cryptography_primitives.smithygenerated.aws_cryptography_primitives.models import ECDHCurveSpec

# Instantiate the material providers library
mat_prov: AwsCryptographicMaterialProviders = AwsCryptographicMaterialProviders(
    config=MaterialProvidersConfig()
)

# Retrieve public keys
# Must be DER-encoded X.509 public keys
bob_public_key = get_public_key_bytes("arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab")
alice_public_key = get_public_key_bytes("arn:aws:kms:us-west-2:111122223333:key/0987dcba-09fe-87dc-65ba-ab0987654321")

# Create the AWS KMS ECDH static keyring
sender_keyring_input = CreateAwsKmsEcdhKeyringInput(
    kms_client = boto3.client('kms', region_name="us-west-2"),
    curve_spec = ECDHCurveSpec.ECC_NIST_P256,
    key_agreement_scheme = KmsEcdhStaticConfigurationsKmsPrivateKeyToStaticPublicKey(
        KmsPrivateKeyToStaticPublicKeyInput(
            sender_kms_identifier = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
            sender_public_key = bob_public_key,
            recipient_public_key = alice_public_key,

        )
    )
)

keyring = mat_prov.create_aws_kms_ecdh_keyring(sender_keyring_input)
```

------
#### [ Rust ]

다음 예제에서는 발신자의 KMS 키, 발신자의 퍼블릭 키 및 수신자의 퍼블릭 키를 사용하여 AWS KMS 로 ECDH 키링을 생성합니다. 이 예제에서는 선택적 `sender_public_key` 파라미터를 사용하여 발신자의 퍼블릭 키를 제공합니다. 발신자의 퍼블릭 키를 제공하지 않으면 키링이를 호출 AWS KMS 하여 발신자의 퍼블릭 키를 검색합니다.

```
// Instantiate the AWS Encryption SDK client
let esdk_config = AwsEncryptionSdkConfig::builder().build()?;
let esdk_client = esdk_client::Client::from_conf(esdk_config)?;

// Create the AWS KMS client
let sdk_config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
let kms_client = aws_sdk_kms::Client::new(&sdk_config);

// Optional: Create your encryption context
let encryption_context = HashMap::from([
    ("encryption".to_string(), "context".to_string()),
    ("is not".to_string(), "secret".to_string()),
    ("but adds".to_string(), "useful metadata".to_string()),
    ("that can help you".to_string(), "be confident that".to_string()),
    ("the data you are handling".to_string(), "is what you think it is".to_string()),
]);

// Retrieve public keys
// Must be DER-encoded X.509 keys
let public_key_file_content_sender = std::fs::read_to_string(Path::new(EXAMPLE_KMS_ECC_PUBLIC_KEY_FILENAME_SENDER))?;
let parsed_public_key_file_content_sender = parse(public_key_file_content_sender)?;
let public_key_sender_utf8_bytes = parsed_public_key_file_content_sender.contents();

let public_key_file_content_recipient = std::fs::read_to_string(Path::new(EXAMPLE_KMS_ECC_PUBLIC_KEY_FILENAME_RECIPIENT))?;
let parsed_public_key_file_content_recipient = parse(public_key_file_content_recipient)?;
let public_key_recipient_utf8_bytes = parsed_public_key_file_content_recipient.contents();

// Create KmsPrivateKeyToStaticPublicKeyInput
let kms_ecdh_static_configuration_input =
    KmsPrivateKeyToStaticPublicKeyInput::builder()
        .sender_kms_identifier(arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab)
        // Must be a UTF8 DER-encoded X.509 public key
        .sender_public_key(public_key_sender_utf8_bytes)
        // Must be a UTF8 DER-encoded X.509 public key
        .recipient_public_key(public_key_recipient_utf8_bytes)
        .build()?;

let kms_ecdh_static_configuration = KmsEcdhStaticConfigurations::KmsPrivateKeyToStaticPublicKey(kms_ecdh_static_configuration_input);

// Instantiate the material providers library
let mpl_config = MaterialProvidersConfig::builder().build()?;
let mpl = mpl_client::Client::from_conf(mpl_config)?;

// Create AWS KMS ECDH keyring
let kms_ecdh_keyring = mpl
    .create_aws_kms_ecdh_keyring()
    .kms_client(kms_client)
    .curve_spec(ecdh_curve_spec)
    .key_agreement_scheme(kms_ecdh_static_configuration)
    .send()
    .await?;
```

------
#### [ Go ]

```
import (
    "context"
    
	mpl "aws/aws-cryptographic-material-providers-library/releases/go/mpl/awscryptographymaterialproviderssmithygenerated"
	mpltypes "aws/aws-cryptographic-material-providers-library/releases/go/mpl/awscryptographymaterialproviderssmithygeneratedtypes"
	client "github.com/aws/aws-encryption-sdk/awscryptographyencryptionsdksmithygenerated"
	esdktypes "github.com/aws/aws-encryption-sdk/awscryptographyencryptionsdksmithygeneratedtypes"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/kms"
)

// Instantiate the AWS Encryption SDK client
encryptionClient, err := client.NewClient(esdktypes.AwsEncryptionSdkConfig{})
if err != nil {
    panic(err)
}

// Create an AWS KMS client
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
    panic(err)
}
kmsClient := kms.NewFromConfig(cfg, func(o *kms.Options) {
    o.Region = KmsKeyRegion
})

// Optional: Create an encryption context
encryptionContext := map[string]string{
    "encryption":                "context",
    "is not":                    "secret",
    "but adds":                  "useful metadata",
    "that can help you":         "be confident that",
    "the data you are handling": "is what you think it is",
}

// Retrieve public keys
// Must be DER-encoded X.509 keys
publicKeySender, err := utils.LoadPublicKeyFromPEM(kmsEccPublicKeyFileNameSender)
if err != nil {
    panic(err)
}
publicKeyRecipient, err := utils.LoadPublicKeyFromPEM(kmsEccPublicKeyFileNameRecipient)
if err != nil {
    panic(err)
}

// Create KmsPrivateKeyToStaticPublicKeyInput
kmsEcdhStaticConfigurationInput := mpltypes.KmsPrivateKeyToStaticPublicKeyInput{
    RecipientPublicKey:  publicKeyRecipient,
    SenderKmsIdentifier: arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab,
    SenderPublicKey:     publicKeySender,
}
kmsEcdhStaticConfiguration := &mpltypes.KmsEcdhStaticConfigurationsMemberKmsPrivateKeyToStaticPublicKey{
    Value: kmsEcdhStaticConfigurationInput,
}

// Instantiate the material providers library
matProv, err := mpl.NewClient(mpltypes.MaterialProvidersConfig{})
if err != nil {
    panic(err)
}

// Create AWS KMS ECDH keyring
awsKmsEcdhKeyringInput := mpltypes.CreateAwsKmsEcdhKeyringInput{
    CurveSpec:          ecdhCurveSpec,
    KeyAgreementScheme: kmsEcdhStaticConfiguration,
    KmsClient:          kmsClient,
}
awsKmsEcdhKeyring, err := matProv.CreateAwsKmsEcdhKeyring(context.Background(), awsKmsEcdhKeyringInput)
if err != nil {
    panic(err)
}
```

------

## AWS KMS ECDH 검색 키링 생성
<a name="kms-ecdh-discovery"></a>

복호화할 때는에서 사용할 AWS Encryption SDK 수 있는 키를 지정하는 것이 가장 좋습니다. 이 모범 사례를 따르려면 `KmsPrivateKeyToStaticPublicKey` 키 계약 스키마와 함께 AWS KMS ECDH 키링을 사용합니다. 그러나 AWS KMS ECDH 검색 키링, 즉 지정된 KMS 키 페어의 퍼블릭 키가 메시지 사이퍼텍스트에 저장된 *수신자의* 퍼블릭 키와 일치하는 모든 메시지를 복호화할 수 있는 AWS KMS ECDH 키링을 생성할 수도 있습니다.

**중요**  
`KmsPublicKeyDiscovery` 키 계약 스키마를 사용하여 메시지를 복호화할 때 누가 소유하든 모든 퍼블릭 키를 수락합니다.

`KmsPublicKeyDiscovery` 키 계약 스키마를 사용하여 AWS KMS ECDH 키링을 초기화하려면 다음 값을 제공합니다.
+ **수신자 ID AWS KMS key **

  `KeyUsage` 값이 인 비대칭 NIST 권장 타원 곡선(ECC) KMS 키 페어를 식별해야 합니다`KEY_AGREEMENT`.
+ **곡선 사양**

  수신자의 KMS 키 페어에서 타원 곡선 사양을 식별합니다.

  유효한 값: `ECC_NIST_P256`, `ECC_NIS_P384`, `ECC_NIST_P512` 
+ **(선택 사항) 권한 부여 토큰 목록**

  [권한 부여](https://docs.aws.amazon.com/kms/latest/developerguide/grants.html)를 사용하여 AWS KMS ECDH 키링의 KMS 키에 대한 액세스를 제어하는 경우 키링을 초기화할 때 필요한 모든 권한 부여 토큰을 제공해야 합니다.

------
#### [ C\$1 / .NET ]

다음 예제에서는 `ECC_NIST_P256` 곡선에 KMS 키 페어가 있는 AWS KMS ECDH 검색 키링을 생성합니다. 지정된 KMS 키 페어에 [대해 kms:GetPublicKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GetPublicKey.html) 및 [kms:DeriveSharedSecret](https://docs.aws.amazon.com/kms/latest/APIReference/API_DeriveSharedSecret.html) 권한이 있어야 합니다. 이 키링은 지정된 KMS 키 페어의 퍼블릭 키가 메시지 사이퍼텍스트에 저장된 수신자의 퍼블릭 키와 일치하는 모든 메시지를 복호화할 수 있습니다.

```
// Instantiate material providers
var materialProviders = new MaterialProviders(new MaterialProvidersConfig());

// Create the AWS KMS ECDH discovery keyring
var discoveryConfiguration = new KmsEcdhStaticConfigurations
{
    KmsPublicKeyDiscovery = new KmsPublicKeyDiscoveryInput
    {
        RecipientKmsIdentifier = "arn:aws:kms:us-west-2:111122223333:key/0987dcba-09fe-87dc-65ba-ab0987654321"
    }
		    
};
var createKeyringInput = new CreateAwsKmsEcdhKeyringInput
{
    CurveSpec = ECDHCurveSpec.ECC_NIST_P256,
    KmsClient = new AmazonKeyManagementServiceClient(),
    KeyAgreementScheme = discoveryConfiguration
};
var keyring = materialProviders.CreateAwsKmsEcdhKeyring(createKeyringInput);
```

------
#### [ Java ]

다음 예제에서는 `ECC_NIST_P256` 곡선에 KMS 키 페어가 있는 AWS KMS ECDH 검색 키링을 생성합니다. 지정된 KMS 키 페어에 [대해 kms:GetPublicKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GetPublicKey.html) 및 [kms:DeriveSharedSecret](https://docs.aws.amazon.com/kms/latest/APIReference/API_DeriveSharedSecret.html) 권한이 있어야 합니다. 이 키링은 지정된 KMS 키 페어의 퍼블릭 키가 메시지 사이퍼텍스트에 저장된 수신자의 퍼블릭 키와 일치하는 모든 메시지를 복호화할 수 있습니다.

```
// Create the AWS KMS ECDH discovery keyring
final CreateAwsKmsEcdhKeyringInput recipientKeyringInput =
  CreateAwsKmsEcdhKeyringInput.builder()
    .kmsClient(KmsClient.create())
    .curveSpec(ECDHCurveSpec.ECC_NIST_P256)
    .KeyAgreementScheme(
      KmsEcdhStaticConfigurations.builder()
        .KmsPublicKeyDiscovery(
          KmsPublicKeyDiscoveryInput.builder()
            .recipientKmsIdentifier("arn:aws:kms:us-west-2:111122223333:key/0987dcba-09fe-87dc-65ba-ab0987654321").build()
        ).build())
    .build();
```

------
#### [ Python ]

다음 예제에서는 `ECC_NIST_P256` 곡선에 KMS 키 페어가 있는 AWS KMS ECDH 검색 키링을 생성합니다. 지정된 KMS 키 페어에 [대해 kms:GetPublicKey](https://docs.aws.amazon.com/kms/latest/APIReference/API_GetPublicKey.html) 및 [kms:DeriveSharedSecret](https://docs.aws.amazon.com/kms/latest/APIReference/API_DeriveSharedSecret.html) 권한이 있어야 합니다. 이 키링은 지정된 KMS 키 페어의 퍼블릭 키가 메시지 사이퍼텍스트에 저장된 수신자의 퍼블릭 키와 일치하는 모든 메시지를 복호화할 수 있습니다.

```
import boto3
from aws_cryptographic_materialproviders.mpl.models import (
    CreateAwsKmsEcdhKeyringInput,
    KmsEcdhStaticConfigurationsKmsPublicKeyDiscovery,
    KmsPublicKeyDiscoveryInput,
)
from aws_cryptography_primitives.smithygenerated.aws_cryptography_primitives.models import ECDHCurveSpec

# Instantiate the material providers library
mat_prov: AwsCryptographicMaterialProviders = AwsCryptographicMaterialProviders(
    config=MaterialProvidersConfig()
)

# Create the AWS KMS ECDH discovery keyring
create_keyring_input = CreateAwsKmsEcdhKeyringInput(
    kms_client = boto3.client('kms', region_name="us-west-2"),
    curve_spec = ECDHCurveSpec.ECC_NIST_P256,
    key_agreement_scheme = KmsEcdhStaticConfigurationsKmsPublicKeyDiscovery(
        KmsPublicKeyDiscoveryInput(
            recipient_kms_identifier = "arn:aws:kms:us-west-2:111122223333:key/0987dcba-09fe-87dc-65ba-ab0987654321",
        )
    )
)

keyring = mat_prov.create_aws_kms_ecdh_keyring(create_keyring_input)
```

------
#### [ Rust ]

```
// Instantiate the AWS Encryption SDK client
let esdk_config = AwsEncryptionSdkConfig::builder().build()?;
let esdk_client = esdk_client::Client::from_conf(esdk_config)?;

// Create the AWS KMS client
let sdk_config = aws_config::load_defaults(aws_config::BehaviorVersion::latest()).await;
let kms_client = aws_sdk_kms::Client::new(&sdk_config);

// Optional: Create your encryption context
let encryption_context = HashMap::from([
    ("encryption".to_string(), "context".to_string()),
    ("is not".to_string(), "secret".to_string()),
    ("but adds".to_string(), "useful metadata".to_string()),
    ("that can help you".to_string(), "be confident that".to_string()),
    ("the data you are handling".to_string(), "is what you think it is".to_string()),
]);

// Create KmsPublicKeyDiscoveryInput
let kms_ecdh_discovery_static_configuration_input =
    KmsPublicKeyDiscoveryInput::builder()
        .recipient_kms_identifier(ecc_recipient_key_arn)
        .build()?;

let kms_ecdh_discovery_static_configuration = KmsEcdhStaticConfigurations::KmsPublicKeyDiscovery(kms_ecdh_discovery_static_configuration_input);

// Instantiate the material providers library
let mpl_config = MaterialProvidersConfig::builder().build()?;
let mpl = mpl_client::Client::from_conf(mpl_config)?;

// Create AWS KMS ECDH discovery keyring
let kms_ecdh_discovery_keyring = mpl
    .create_aws_kms_ecdh_keyring()
    .kms_client(kms_client.clone())
    .curve_spec(ecdh_curve_spec)
    .key_agreement_scheme(kms_ecdh_discovery_static_configuration)
    .send()
    .await?;
```

------
#### [ Go ]

```
import (
    "context"
    
	mpl "aws/aws-cryptographic-material-providers-library/releases/go/mpl/awscryptographymaterialproviderssmithygenerated"
	mpltypes "aws/aws-cryptographic-material-providers-library/releases/go/mpl/awscryptographymaterialproviderssmithygeneratedtypes"
	client "github.com/aws/aws-encryption-sdk/awscryptographyencryptionsdksmithygenerated"
	esdktypes "github.com/aws/aws-encryption-sdk/awscryptographyencryptionsdksmithygeneratedtypes"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/kms"
)

// Instantiate the AWS Encryption SDK client
encryptionClient, err := client.NewClient(esdktypes.AwsEncryptionSdkConfig{})
if err != nil {
    panic(err)
}

// Create an AWS KMS client
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
    panic(err)
}
kmsClient := kms.NewFromConfig(cfg, func(o *kms.Options) {
    o.Region = KmsKeyRegion
})

// Optional: Create an encryption context
encryptionContext := map[string]string{
    "encryption":                "context",
    "is not":                    "secret",
    "but adds":                  "useful metadata",
    "that can help you":         "be confident that",
    "the data you are handling": "is what you think it is",
}

// Create KmsPublicKeyDiscoveryInput
kmsEcdhDiscoveryStaticConfigurationInput := mpltypes.KmsPublicKeyDiscoveryInput{
    RecipientKmsIdentifier: eccRecipientKeyArn,
}
kmsEcdhDiscoveryStaticConfiguration := &mpltypes.KmsEcdhStaticConfigurationsMemberKmsPublicKeyDiscovery{
    Value: kmsEcdhDiscoveryStaticConfigurationInput,
}

// Instantiate the material providers library
matProv, err := mpl.NewClient(mpltypes.MaterialProvidersConfig{})
if err != nil {
    panic(err)
}

// Create AWS KMS ECDH discovery keyring
awsKmsEcdhDiscoveryKeyringInput := mpltypes.CreateAwsKmsEcdhKeyringInput{
    CurveSpec:          ecdhCurveSpec,
    KeyAgreementScheme: kmsEcdhDiscoveryStaticConfiguration,
    KmsClient:          kmsClient,
}
awsKmsEcdhDiscoveryKeyring, err := matProv.CreateAwsKmsEcdhKeyring(context.Background(), awsKmsEcdhDiscoveryKeyringInput)
if err != nil {
    panic(err)
}
```

------