

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Raw ECDH キーリング
<a name="use-raw-ecdh-keyring"></a>

Raw ECDH キーリングは、指定した楕円曲線のパブリック/プライベートキーペアを使用して、2 つの当事者間で共有ラッピングキーを取得します。まず、キーリングは、送信者のプライベートキー、受信者のパブリックキー、および楕円曲線 Diffie-Hellman (ECDH) キーアグリーメントアルゴリズムを使用して共有シークレットを取得します。次に、キーリングは共有シークレットを使用して、データ暗号化キーを保護する共有ラッピングキーを取得します。が (`KDF_CTR_HMAC_SHA384`) AWS Encryption SDK を使用して共有ラッピングキーを取得するキー取得関数は、[キー取得に関する NIST レコメンデーション](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-108r1-upd1.pdf)に準拠しています。

キー取得関数は、64 バイトのキーマテリアルを返します。両当事者が正しいキーマテリアルを使用していることを確認するために、 AWS Encryption SDK は最初の 32 バイトをコミットメントキーとして使用し、最後の 32 バイトを共有ラッピングキーとして使用します。復号時に、キーリングがメッセージヘッダー暗号文に保存されているのと同じコミットメントキーと共有ラッピングキーを再現できない場合、オペレーションは失敗します。たとえば、**Alice の**プライベートキーと **Bob** のパブリックキーで設定されたキーリングを使用してデータを暗号化する場合、**Bob の**プライベートキーと **Alice の**パブリックキーで設定されたキーリングは、同じコミットメントキーと共有ラッピングキーを再現し、データを復号化できます。Bob のパブリックキーが AWS KMS key ペアからのものである場合、Bob は [AWS KMS ECDH キーリング](use-kms-ecdh-keyring.md)を作成してデータを復号できます。

Raw ECDH キーリングは、AES-GCM を使用して対称キーでデータを暗号化します。次に、データキーは、AES-GCM を使用して派生した共有ラッピングキーでエンベロープ暗号化されます。各 Raw ECDH キーリングには 1 つの共有ラッピングキーのみを含めることができますが、複数の Raw ECDH キーリングを単独で、または他のキーリングと共に[マルチキーリング](use-multi-keyring.md)に含めることができます。

プライベートキーの生成、保存、保護は、ハードウェアセキュリティモジュール (HSM) またはキー管理システムで行うことをお勧めします。送信者と受信者のキーペアは、ほぼ同じ楕円曲線上にあります。は、次の楕円曲線仕様 AWS Encryption SDK をサポートしています。
+ `ECC_NIST_P256`
+ `ECC_NIST_P384`
+ `ECC_NIST_P512`

**プログラミング言語の互換性**  
Raw ECDH キーリングは [Cryptographic Material Providers Library](https://github.com/aws/aws-cryptographic-material-providers-library) (MPL) のバージョン 1.5.0 で導入され、次のプログラミング言語とバージョンでサポートされています。
+ のバージョン 3.*x* AWS Encryption SDK for Java
+  AWS Encryption SDK for .NET のバージョン 4.*x* 以降
+ オプションの MPL 依存関係で使用する AWS Encryption SDK for Python場合のバージョン 4.*x*。
+  AWS Encryption SDK for Rust のバージョン 1.*x* 
+  AWS Encryption SDK for Go のバージョン 0.1.*x* 以降

## Raw ECDH キーリングの作成
<a name="raw-ecdh-create"></a>

Raw ECDH キーリングは、`RawPrivateKeyToStaticPublicKey`、、 `EphemeralPrivateKeyToStaticPublicKey`の 3 つのキーアグリーメントスキーマをサポートしています`PublicKeyDiscovery`。選択したキーアグリーメントスキーマによって、実行できる暗号化オペレーションとキーマテリアルの組み立て方法が決まります。

**Topics**
+ [RawPrivateKeyToStaticPublicKey](#raw-ecdh-RawPrivateKeyToStaticPublicKey)
+ [EphemeralPrivateKeyToStaticPublicKey](#raw-ecdh-EphemeralPrivateKeyToStaticPublicKey)
+ [PublicKeyDiscovery](#raw-ecdh-PublicKeyDiscovery)

### RawPrivateKeyToStaticPublicKey
<a name="raw-ecdh-RawPrivateKeyToStaticPublicKey"></a>

`RawPrivateKeyToStaticPublicKey` キーアグリーメントスキーマを使用して、送信者のプライベートキーと受信者のパブリックキーをキーリングに静的に設定します。このキーアグリーメントスキーマは、データを暗号化および復号化できます。

`RawPrivateKeyToStaticPublicKey` キーアグリーメントスキーマを使用して Raw ECDH キーリングを初期化するには、次の値を指定します。
+ **送信者のプライベートキー**

  [RFC 595](https://tools.ietf.org/html/rfc5958#section-2)8 で定義されているように、送信者の PEM エンコードされたプライベートキー (PKCS \#8 PrivateKeyInfo 構造) を指定する必要があります。
+ **受信者のパブリックキー**

  RFC 5280 で定義されているように、(`SubjectPublicKeyInfo`SPKI) とも呼ばれる受信者の DER エンコードされた X.509 パブリックキーを指定する必要があります。 [https://tools.ietf.org/html/rfc5280](https://tools.ietf.org/html/rfc5280)

  非対称キーアグリーメント KMS キーペアのパブリックキー、または の外部で生成されたキーペアのパブリックキーを指定できます AWS。
+ **曲線仕様**

  指定されたキーペアの楕円曲線仕様を識別します。送信者と受信者の両方のキーペアは、同じ曲線仕様である必要があります。

  有効な値: `ECC_NIST_P256`、`ECC_NIS_P384`、`ECC_NIST_P512`

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

```
// Instantiate material providers
var materialProviders = new MaterialProviders(new MaterialProvidersConfig());
	    var BobPrivateKey = new MemoryStream(new byte[] { });
	    var AlicePublicKey = new MemoryStream(new byte[] { });

	    // Create the Raw ECDH static keyring
	    var staticConfiguration = new RawEcdhStaticConfigurations()
	    {
		    RawPrivateKeyToStaticPublicKey = new RawPrivateKeyToStaticPublicKeyInput
		    {
			    SenderStaticPrivateKey = BobPrivateKey,
			    RecipientPublicKey = AlicePublicKey
		    }
	    };
	    
	    var createKeyringInput = new CreateRawEcdhKeyringInput() 
	    {
		    CurveSpec = ECDHCurveSpec.{{ECC_NIST_P256}},
		    KeyAgreementScheme = staticConfiguration 
	    };

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

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

次の Java の例では、`RawPrivateKeyToStaticPublicKey`キーアグリーメントスキーマを使用して、送信者のプライベートキーと受信者のパブリックキーを静的に設定します。両方のキーペアが`ECC_NIST_P256`曲線上にあります。

```
private static void StaticRawKeyring() {
    // Instantiate material providers
    final MaterialProviders materialProviders =
      MaterialProviders.builder()
        .MaterialProvidersConfig(MaterialProvidersConfig.builder().build())
        .build();

    KeyPair senderKeys = GetRawEccKey();
    KeyPair recipient = GetRawEccKey();

    // Create the Raw ECDH static keyring
    final CreateRawEcdhKeyringInput rawKeyringInput =
      CreateRawEcdhKeyringInput.builder()
        .curveSpec(ECDHCurveSpec.{{ECC_NIST_P256}})
        .KeyAgreementScheme(
          RawEcdhStaticConfigurations.builder()
            .RawPrivateKeyToStaticPublicKey(
                RawPrivateKeyToStaticPublicKeyInput.builder()
                  // Must be a PEM-encoded private key
                  .senderStaticPrivateKey(ByteBuffer.wrap(senderKeys.getPrivate().getEncoded()))
                  // Must be a DER-encoded X.509 public key
                  .recipientPublicKey(ByteBuffer.wrap(recipient.getPublic().getEncoded()))
                  .build()
            )
            .build()
        ).build();

    final IKeyring staticKeyring = materialProviders.CreateRawEcdhKeyring(rawKeyringInput);
}
```

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

次の Python の例では、`RawEcdhStaticConfigurationsRawPrivateKeyToStaticPublicKey`キーアグリーメントスキーマを使用して、送信者のプライベートキーと受信者のパブリックキーを静的に設定します。両方のキーペアが`ECC_NIST_P256`曲線上にあります。

```
import boto3
from aws_cryptographic_materialproviders.mpl.models import (
    CreateRawEcdhKeyringInput,
    RawEcdhStaticConfigurationsRawPrivateKeyToStaticPublicKey,
    RawPrivateKeyToStaticPublicKeyInput,
)
from aws_cryptography_primitives.smithygenerated.aws_cryptography_primitives.models import ECDHCurveSpec

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

# Must be a PEM-encoded private key
bob_private_key = get_private_key_bytes()
# Must be a DER-encoded X.509 public key
alice_public_key = get_public_key_bytes()

# Create the raw ECDH static keyring
raw_keyring_input = CreateRawEcdhKeyringInput(
    curve_spec = ECDHCurveSpec.{{ECC_NIST_P256}},
    key_agreement_scheme = RawEcdhStaticConfigurationsRawPrivateKeyToStaticPublicKey(
        RawPrivateKeyToStaticPublicKeyInput(
            sender_static_private_key = bob_private_key,
            recipient_public_key = alice_public_key,
        )
    )
)

keyring = mat_prov.create_raw_ecdh_keyring(raw_keyring_input)
```

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

次の Python の例では、`raw_ecdh_static_configuration`キーアグリーメントスキーマを使用して、送信者のプライベートキーと受信者のパブリックキーを静的に設定します。両方のキーペアが同じ曲線上にある必要があります。

```
// Instantiate the AWS Encryption SDK client
let esdk_config = AwsEncryptionSdkConfig::builder().build()?;
let esdk_client = esdk_client::Client::from_conf(esdk_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 keyring input
let raw_ecdh_static_configuration_input =
    RawPrivateKeyToStaticPublicKeyInput::builder()
        // Must be a UTF8 PEM-encoded private key
        .sender_static_private_key(private_key_sender_utf8_bytes)
        // Must be a UTF8 DER-encoded X.509 public key
        .recipient_public_key(public_key_recipient_utf8_bytes)
        .build()?;

let raw_ecdh_static_configuration = RawEcdhStaticConfigurations::RawPrivateKeyToStaticPublicKey(raw_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 raw ECDH static keyring
let raw_ecdh_keyring = mpl
    .create_raw_ecdh_keyring()
    .curve_spec(ecdh_curve_spec)
    .key_agreement_scheme(raw_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"
)

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

// Optional: Create your 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 keyring input
rawEcdhStaticConfigurationInput := mpltypes.RawPrivateKeyToStaticPublicKeyInput{
    SenderStaticPrivateKey: privateKeySender,
    RecipientPublicKey:     publicKeyRecipient,
}
rawECDHStaticConfiguration := &mpltypes.RawEcdhStaticConfigurationsMemberRawPrivateKeyToStaticPublicKey{
    Value: rawEcdhStaticConfigurationInput,
}
rawEcdhKeyRingInput := mpltypes.CreateRawEcdhKeyringInput{
    CurveSpec:          ecdhCurveSpec,
    KeyAgreementScheme: rawECDHStaticConfiguration,
}

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

// Create raw ECDH static keyring
rawEcdhKeyring, err := matProv.CreateRawEcdhKeyring(context.Background(), rawEcdhKeyRingInput)
if err != nil {
    panic(err)
}
```

------

### EphemeralPrivateKeyToStaticPublicKey
<a name="raw-ecdh-EphemeralPrivateKeyToStaticPublicKey"></a>

キーアグリーメントスキーマで設定された`EphemeralPrivateKeyToStaticPublicKey`キーリングは、ローカルに新しいキーペアを作成し、暗号化呼び出しごとに一意の共有ラッピングキーを取得します。

このキーアグリーメントスキーマは、メッセージのみを暗号化できます。`EphemeralPrivateKeyToStaticPublicKey` キーアグリーメントスキーマで暗号化されたメッセージを復号するには、同じ受信者のパブリックキーで設定された検出キーアグリーメントスキーマを使用する必要があります。復号するには、[`PublicKeyDiscovery`](#raw-ecdh-PublicKeyDiscovery)キーアグリーメントアルゴリズムで Raw ECDH キーリングを使用するか、受信者のパブリックキーが非対称キーアグリーメント KMS キーペアからのものである場合は、[KmsPublicKeyDiscovery](use-kms-ecdh-keyring.md#kms-ecdh-discovery) キーアグリーメントスキーマで AWS KMS ECDH キーリングを使用できます。

`EphemeralPrivateKeyToStaticPublicKey` キーアグリーメントスキーマを使用して Raw ECDH キーリングを初期化するには、次の値を指定します。
+ **受信者のパブリックキー**

  RFC 5280 で定義されているように、(`SubjectPublicKeyInfo`SPKI) とも呼ばれる受信者の DER エンコードされた X.509 パブリックキーを指定する必要があります。 [https://tools.ietf.org/html/rfc5280](https://tools.ietf.org/html/rfc5280)

  非対称キーアグリーメント KMS キーペアのパブリックキー、または の外部で生成されたキーペアのパブリックキーを指定できます AWS。
+ **曲線仕様**

  指定されたパブリックキーの楕円曲線仕様を識別します。

  暗号化時に、キーリングは指定された曲線に新しいキーペアを作成し、新しいプライベートキーと指定されたパブリックキーを使用して共有ラッピングキーを取得します。

  有効な値: `ECC_NIST_P256`、`ECC_NIS_P384`、`ECC_NIST_P512`

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

次の の例では、キーアグリーメントスキーマを使用して Raw ECDH `EphemeralPrivateKeyToStaticPublicKey`キーリングを作成します。暗号化時に、キーリングは指定された`ECC_NIST_P256`曲線に新しいキーペアをローカルに作成します。

```
// Instantiate material providers
var materialProviders = new MaterialProviders(new MaterialProvidersConfig());
	    var AlicePublicKey = new MemoryStream(new byte[] { });

	    // Create the Raw ECDH ephemeral keyring
	    var ephemeralConfiguration = new RawEcdhStaticConfigurations()
	    {
		    EphemeralPrivateKeyToStaticPublicKey = new EphemeralPrivateKeyToStaticPublicKeyInput
		    {
			    RecipientPublicKey = AlicePublicKey
		    }
	    };
	    
	    var createKeyringInput = new CreateRawEcdhKeyringInput() 
	    {
		    CurveSpec = ECDHCurveSpec.{{ECC_NIST_P256}},
		    KeyAgreementScheme = ephemeralConfiguration
	    };

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

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

次の の例では、キーアグリーメントスキーマを使用して Raw ECDH `EphemeralPrivateKeyToStaticPublicKey`キーリングを作成します。暗号化時に、キーリングは指定された`ECC_NIST_P256`曲線に新しいキーペアをローカルに作成します。

```
private static void EphemeralRawEcdhKeyring() {
    // Instantiate material providers
    final MaterialProviders materialProviders =
      MaterialProviders.builder()
        .MaterialProvidersConfig(MaterialProvidersConfig.builder().build())
        .build();

    ByteBuffer recipientPublicKey = getPublicKeyBytes();

    // Create the Raw ECDH ephemeral keyring
    final CreateRawEcdhKeyringInput ephemeralInput =
      CreateRawEcdhKeyringInput.builder()
        .curveSpec(ECDHCurveSpec.{{ECC_NIST_P256}})
        .KeyAgreementScheme(
          RawEcdhStaticConfigurations.builder()
            .EphemeralPrivateKeyToStaticPublicKey(
              EphemeralPrivateKeyToStaticPublicKeyInput.builder()
                .recipientPublicKey(recipientPublicKey)
                .build()
            )
            .build()
        ).build();

    final IKeyring ephemeralKeyring = materialProviders.CreateRawEcdhKeyring(ephemeralInput);
}
```

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

次の の例では、キーアグリーメントスキーマを使用して Raw ECDH `RawEcdhStaticConfigurationsEphemeralPrivateKeyToStaticPublicKey`キーリングを作成します。暗号化時に、キーリングは指定された`ECC_NIST_P256`曲線に新しいキーペアをローカルに作成します。

```
import boto3
from aws_cryptographic_materialproviders.mpl.models import (
    CreateRawEcdhKeyringInput,
    RawEcdhStaticConfigurationsEphemeralPrivateKeyToStaticPublicKey,
    EphemeralPrivateKeyToStaticPublicKeyInput,
)
from aws_cryptography_primitives.smithygenerated.aws_cryptography_primitives.models import ECDHCurveSpec

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

# Your get_public_key_bytes must return a DER-encoded X.509 public key
recipient_public_key = get_public_key_bytes()

# Create the raw ECDH ephemeral private key keyring
ephemeral_input = CreateRawEcdhKeyringInput(
    curve_spec = ECDHCurveSpec.{{ECC_NIST_P256}},
    key_agreement_scheme = RawEcdhStaticConfigurationsEphemeralPrivateKeyToStaticPublicKey(
        EphemeralPrivateKeyToStaticPublicKeyInput(
            recipient_public_key = recipient_public_key,
        )
    )
)

keyring = mat_prov.create_raw_ecdh_keyring(ephemeral_input)
```

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

次の の例では、キーアグリーメントスキーマを使用して Raw ECDH `ephemeral_raw_ecdh_static_configuration`キーリングを作成します。暗号化時に、キーリングは指定された曲線に新しいキーペアをローカルに作成します。

```
// Instantiate the AWS Encryption SDK client
let esdk_config = AwsEncryptionSdkConfig::builder().build()?;
let esdk_client = esdk_client::Client::from_conf(esdk_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()),
]);

// Load public key from UTF-8 encoded PEM files into a DER encoded public key.
let public_key_file_content = std::fs::read_to_string(Path::new(EXAMPLE_ECC_PUBLIC_KEY_FILENAME_RECIPIENT))?;
let parsed_public_key_file_content = parse(public_key_file_content)?;
let public_key_recipient_utf8_bytes = parsed_public_key_file_content.contents();

// Create EphemeralPrivateKeyToStaticPublicKeyInput
let ephemeral_raw_ecdh_static_configuration_input =
    EphemeralPrivateKeyToStaticPublicKeyInput::builder()
        // Must be a UTF8 DER-encoded X.509 public key
        .recipient_public_key(public_key_recipient_utf8_bytes)
        .build()?;

let ephemeral_raw_ecdh_static_configuration =
    RawEcdhStaticConfigurations::EphemeralPrivateKeyToStaticPublicKey(ephemeral_raw_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 raw ECDH ephemeral private key keyring
let ephemeral_raw_ecdh_keyring = mpl
    .create_raw_ecdh_keyring()
    .curve_spec(ecdh_curve_spec)
    .key_agreement_scheme(ephemeral_raw_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"
)

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

// Optional: Create your 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",
}

// Load public key from UTF-8 encoded PEM files into a DER encoded public key
publicKeyRecipient, err := LoadPublicKeyFromPEM(eccPublicKeyFileNameRecipient)
if err != nil {
    panic(err)
}

// Create EphemeralPrivateKeyToStaticPublicKeyInput
ephemeralRawEcdhStaticConfigurationInput := mpltypes.EphemeralPrivateKeyToStaticPublicKeyInput{
    RecipientPublicKey: publicKeyRecipient,
}
ephemeralRawECDHStaticConfiguration :=
    mpltypes.RawEcdhStaticConfigurationsMemberEphemeralPrivateKeyToStaticPublicKey{
        Value: ephemeralRawEcdhStaticConfigurationInput,
    }

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

// Create raw ECDH ephemeral private key keyring
rawEcdhKeyRingInput := mpltypes.CreateRawEcdhKeyringInput{
    CurveSpec:          ecdhCurveSpec,
    KeyAgreementScheme: &ephemeralRawECDHStaticConfiguration,
}
ecdhKeyring, err := matProv.CreateRawEcdhKeyring(context.Background(), rawEcdhKeyRingInput)
if err != nil {
    panic(err)
}
```

------

### PublicKeyDiscovery
<a name="raw-ecdh-PublicKeyDiscovery"></a>

復号するときは、 で使用できるラッピングキーを指定するのがベストプラクティスです AWS Encryption SDK 。このベストプラクティスに従うには、送信者のプライベートキーと受信者のパブリックキーの両方を指定する ECDH キーリングを使用します。ただし、Raw ECDH 検出キーリング、つまり、指定されたキーのパブリックキーがメッセージ暗号文に保存されている受信者のパブリックキーと一致するメッセージを復号できる Raw ECDH キーリングを作成することもできます。このキーアグリーメントスキーマはメッセージを復号化することしかできません。

**重要**  
`PublicKeyDiscovery` キーアグリーメントスキーマを使用してメッセージを復号する場合、その所有者に関係なく、すべてのパブリックキーを受け入れます。

`PublicKeyDiscovery` キーアグリーメントスキーマを使用して Raw ECDH キーリングを初期化するには、次の値を指定します。
+ **受信者の静的プライベートキー**

  [RFC 595](https://tools.ietf.org/html/rfc5958#section-2)8 で定義されているように、受信者の PEM エンコードされたプライベートキー (PKCS \#8 PrivateKeyInfo 構造) を指定する必要があります。
+ **曲線仕様**

  指定されたプライベートキーの楕円曲線仕様を識別します。送信者と受信者の両方のキーペアは、同じ曲線仕様である必要があります。

  有効な値: `ECC_NIST_P256`、`ECC_NIS_P384`、`ECC_NIST_P512`

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

次の例では、キーアグリーメントスキーマを使用して Raw ECDH `PublicKeyDiscovery`キーリングを作成します。このキーリングは、指定されたプライベートキーのパブリックキーが、メッセージ暗号文に保存されている受信者のパブリックキーと一致するメッセージを復号できます。

```
// Instantiate material providers
var materialProviders = new MaterialProviders(new MaterialProvidersConfig());
	    var AlicePrivateKey = new MemoryStream(new byte[] { });

	    // Create the Raw ECDH discovery keyring
	    var discoveryConfiguration = new RawEcdhStaticConfigurations()
	    {
		    PublicKeyDiscovery = new PublicKeyDiscoveryInput
		    {
			    RecipientStaticPrivateKey = AlicePrivateKey
		    }
	    };
	    
	    var createKeyringInput = new CreateRawEcdhKeyringInput() 
	    {
		    CurveSpec = ECDHCurveSpec.ECC_NIST_P256,
		    KeyAgreementScheme = discoveryConfiguration 
	    };

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

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

次の例では、キーアグリーメントスキーマを使用して Raw ECDH `PublicKeyDiscovery`キーリングを作成します。このキーリングは、指定されたプライベートキーのパブリックキーが、メッセージ暗号文に保存されている受信者のパブリックキーと一致するメッセージを復号できます。

```
private static void RawEcdhDiscovery() {
    // Instantiate material providers
    final MaterialProviders materialProviders =
      MaterialProviders.builder()
        .MaterialProvidersConfig(MaterialProvidersConfig.builder().build())
        .build();

    KeyPair recipient = GetRawEccKey();

    // Create the Raw ECDH discovery keyring
    final CreateRawEcdhKeyringInput rawKeyringInput =
      CreateRawEcdhKeyringInput.builder()
        .curveSpec(ECDHCurveSpec.{{ECC_NIST_P256}})
        .KeyAgreementScheme(
          RawEcdhStaticConfigurations.builder()
            .PublicKeyDiscovery(
              PublicKeyDiscoveryInput.builder()
                // Must be a PEM-encoded private key
                .recipientStaticPrivateKey(ByteBuffer.wrap(sender.getPrivate().getEncoded()))
                .build()
            )
            .build()
        ).build();

    final IKeyring publicKeyDiscovery  = materialProviders.CreateRawEcdhKeyring(rawKeyringInput);
}
```

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

次の例では、キーアグリーメントスキーマを使用して Raw ECDH `RawEcdhStaticConfigurationsPublicKeyDiscovery`キーリングを作成します。このキーリングは、指定されたプライベートキーのパブリックキーが、メッセージ暗号文に保存されている受信者のパブリックキーと一致するメッセージを復号できます。

```
import boto3
from aws_cryptographic_materialproviders.mpl.models import (
    CreateRawEcdhKeyringInput,
    RawEcdhStaticConfigurationsPublicKeyDiscovery,
    PublicKeyDiscoveryInput,
)
from aws_cryptography_primitives.smithygenerated.aws_cryptography_primitives.models import ECDHCurveSpec

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

# Your get_private_key_bytes must return a PEM-encoded private key
recipient_private_key = get_private_key_bytes()

# Create the raw ECDH discovery keyring
raw_keyring_input = CreateRawEcdhKeyringInput(
    curve_spec = ECDHCurveSpec.{{ECC_NIST_P256}},
    key_agreement_scheme = RawEcdhStaticConfigurationsPublicKeyDiscovery(
        PublicKeyDiscoveryInput(
            recipient_static_private_key = recipient_private_key,
        )
    )
)

keyring = mat_prov.create_raw_ecdh_keyring(raw_keyring_input)
```

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

次の例では、キーアグリーメントスキーマを使用して Raw ECDH `discovery_raw_ecdh_static_configuration`キーリングを作成します。このキーリングは、指定されたプライベートキーのパブリックキーが、メッセージ暗号文に保存されている受信者のパブリックキーと一致するメッセージを復号できます。

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

let mpl_config = MaterialProvidersConfig::builder().build()?;
let mpl = mpl_client::Client::from_conf(mpl_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()),
]);

// Load keys from UTF-8 encoded PEM files.
let mut file = File::open(Path::new(EXAMPLE_ECC_PRIVATE_KEY_FILENAME_RECIPIENT))?;
let mut private_key_recipient_utf8_bytes = Vec::new();
file.read_to_end(&mut private_key_recipient_utf8_bytes)?;

// Create PublicKeyDiscoveryInput
let discovery_raw_ecdh_static_configuration_input =
    PublicKeyDiscoveryInput::builder()
        // Must be a UTF8 PEM-encoded private key
        .recipient_static_private_key(private_key_recipient_utf8_bytes)
        .build()?;

let discovery_raw_ecdh_static_configuration =
    RawEcdhStaticConfigurations::PublicKeyDiscovery(discovery_raw_ecdh_static_configuration_input);

// Create raw ECDH discovery private key keyring
let discovery_raw_ecdh_keyring = mpl
    .create_raw_ecdh_keyring()
    .curve_spec(ecdh_curve_spec)
    .key_agreement_scheme(discovery_raw_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"
)

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

// Optional: Create your 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",
}

// Load keys from UTF-8 encoded PEM files.
privateKeyRecipient, err := os.ReadFile(eccPrivateKeyFileNameRecipient)
if err != nil {
    panic(err)
}

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

// Create PublicKeyDiscoveryInput
discoveryRawEcdhStaticConfigurationInput := mpltypes.PublicKeyDiscoveryInput{
    RecipientStaticPrivateKey: privateKeyRecipient,
}

discoveryRawEcdhStaticConfiguration := &mpltypes.RawEcdhStaticConfigurationsMemberPublicKeyDiscovery{
    Value: discoveryRawEcdhStaticConfigurationInput,
}

// Create raw ECDH discovery private key keyring
discoveryRawEcdhKeyringInput := mpltypes.CreateRawEcdhKeyringInput{
    CurveSpec:          ecdhCurveSpec,
    KeyAgreementScheme: discoveryRawEcdhStaticConfiguration,
}

discoveryRawEcdhKeyring, err := matProv.CreateRawEcdhKeyring(context.Background(), discoveryRawEcdhKeyringInput)
if err != nil {
    panic(err)
}
```

------