AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
This is the response object from the CreateKey operation.
Namespace: Amazon.KeyManagementService.Model
Assembly: AWSSDK.KeyManagementService.dll
Version: 3.x.y.z
public class CreateKeyResponse : AmazonWebServiceResponse
The CreateKeyResponse type exposes the following members
Name | Description | |
---|---|---|
![]() |
CreateKeyResponse() |
Name | Type | Description | |
---|---|---|---|
![]() |
ContentLength | System.Int64 | Inherited from Amazon.Runtime.AmazonWebServiceResponse. |
![]() |
HttpStatusCode | System.Net.HttpStatusCode | Inherited from Amazon.Runtime.AmazonWebServiceResponse. |
![]() |
KeyMetadata | Amazon.KeyManagementService.Model.KeyMetadata |
Gets and sets the property KeyMetadata. Metadata associated with the KMS key. |
![]() |
ResponseMetadata | Amazon.Runtime.ResponseMetadata | Inherited from Amazon.Runtime.AmazonWebServiceResponse. |
The following example creates a symmetric KMS key for encryption and decryption. No parameters are required for this operation.
var client = new AmazonKeyManagementServiceClient(); var response = client.CreateKey(new CreateKeyRequest { }); KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.
This example creates a KMS key that contains an asymmetric RSA key pair for encryption and decryption. The key spec and key usage can't be changed after the key is created.
var client = new AmazonKeyManagementServiceClient(); var response = client.CreateKey(new CreateKeyRequest { KeySpec = "RSA_4096", // Describes the type of key material in the KMS key. KeyUsage = "ENCRYPT_DECRYPT" // The cryptographic operations for which you can use the KMS key. }); KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.
This example creates a KMS key that contains an asymmetric elliptic curve (ECC) key pair for signing and verification. The key usage is required even though "SIGN_VERIFY" is the only valid value for ECC KMS keys. The key spec and key usage can't be changed after the key is created.
var client = new AmazonKeyManagementServiceClient(); var response = client.CreateKey(new CreateKeyRequest { KeySpec = "ECC_NIST_P521", // Describes the type of key material in the KMS key. KeyUsage = "SIGN_VERIFY" // The cryptographic operations for which you can use the KMS key. }); KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.
This example creates a 384-bit symmetric HMAC KMS key. The GENERATE_VERIFY_MAC key usage value is required even though it's the only valid value for HMAC KMS keys. The key spec and key usage can't be changed after the key is created.
var client = new AmazonKeyManagementServiceClient(); var response = client.CreateKey(new CreateKeyRequest { KeySpec = "HMAC_384", // Describes the type of key material in the KMS key. KeyUsage = "GENERATE_VERIFY_MAC" // The cryptographic operations for which you can use the KMS key. }); KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.
This example creates a multi-Region primary symmetric encryption key. Because the default values for all parameters create a symmetric encryption key, only the MultiRegion parameter is required for this KMS key.
var client = new AmazonKeyManagementServiceClient(); var response = client.CreateKey(new CreateKeyRequest { MultiRegion = true // Indicates whether the KMS key is a multi-Region (True) or regional (False) key. }); KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.
This example creates a symmetric KMS key with no key material. When the operation is complete, you can import your own key material into the KMS key. To create this KMS key, set the Origin parameter to EXTERNAL.
var client = new AmazonKeyManagementServiceClient(); var response = client.CreateKey(new CreateKeyRequest { Origin = "EXTERNAL" // The source of the key material for the KMS key. }); KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.
This example creates a KMS key in the specified AWS CloudHSM key store. The operation creates the KMS key and its metadata in AWS KMS and creates the key material in the AWS CloudHSM cluster associated with the custom key store. This example requires the CustomKeyStoreId and Origin parameters.
var client = new AmazonKeyManagementServiceClient(); var response = client.CreateKey(new CreateKeyRequest { CustomKeyStoreId = "cks-1234567890abcdef0", // Identifies the custom key store that hosts the KMS key. Origin = "AWS_CLOUDHSM" // Indicates the source of the key material for the KMS key. }); KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.
This example creates a KMS key in the specified external key store. It uses the XksKeyId parameter to associate the KMS key with an existing symmetric encryption key in your external key manager. This CustomKeyStoreId, Origin, and XksKeyId parameters are required in this operation.
var client = new AmazonKeyManagementServiceClient(); var response = client.CreateKey(new CreateKeyRequest { CustomKeyStoreId = "cks-9876543210fedcba9", // Identifies the custom key store that hosts the KMS key. Origin = "EXTERNAL_KEY_STORE", // Indicates the source of the key material for the KMS key. XksKeyId = "bb8562717f809024" // Identifies the encryption key in your external key manager that is associated with the KMS key }); KeyMetadata keyMetadata = response.KeyMetadata; // Detailed information about the KMS key that this operation creates.
.NET:
Supported in: 8.0 and newer, Core 3.1
.NET Standard:
Supported in: 2.0
.NET Framework:
Supported in: 4.5 and newer, 3.5