KMS / Client / encapsulate
encapsulate¶
- KMS.Client.encapsulate(**kwargs)¶
Generates a shared secret and its encapsulated (ciphertext) form using the public key of an ML-KEM KMS key pair. Module-Lattice-Based Key-Encapsulation Mechanism (ML-KEM), specified in FIPS 203 on the NIST website, is a post-quantum algorithm for establishing a shared secret between two parties.
For an example of how two parties establish a shared secret over an insecure channel using ML-KEM, see ML-KEM keys in KMS in the Key Management Service Developer Guide.
The Encapsulate operation is not available in China Regions.
The KMS key that you use for this operation must be in a compatible key state. For details, see Key states of KMS keys in the Key Management Service Developer Guide.
Cross-account use: Yes. To perform this operation with a KMS key in a different Amazon Web Services account, specify the key ARN or alias ARN in the value of the
KeyIdparameter.Required permissions: kms:Encapsulate (key policy)
Related operations:
Decapsulate
DeriveSharedSecret
CreateKey
GetPublicKey
DescribeKey
Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.
See also: AWS API Documentation
Request Syntax
response = client.encapsulate( KeyId='string', EncapsulationAlgorithm='ML_KEM', GrantTokens=[ 'string', ], DryRun=True|False )
- Parameters:
KeyId (string) –
[REQUIRED]
Identifies an asymmetric ML-KEM KMS key. KMS uses the public key in the specified key pair to encapsulate the shared secret. ML-KEM KMS keys have a
KeySpecvalue ofML_KEM_512,ML_KEM_768, orML_KEM_1024and aKeyUsagevalue ofENCAPSULATE_DECAPSULATE. To find theKeySpecandKeyUsageof a KMS key, use the DescribeKey operation.To specify a KMS key, use its key ID, key ARN, alias name, or alias ARN. When using an alias name, prefix it with
"alias/". To specify a KMS key in a different Amazon Web Services account, you must use the key ARN or alias ARN.For example:
Key ID:
1234abcd-12ab-34cd-56ef-1234567890abKey ARN:
arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890abAlias name:
alias/ExampleAliasAlias ARN:
arn:aws:kms:us-east-2:111122223333:alias/ExampleAlias
To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.
EncapsulationAlgorithm (string) –
[REQUIRED]
Specifies the key encapsulation algorithm used to generate the shared secret and its encapsulated form. The only valid value is
ML_KEM.GrantTokens (list) –
A list of grant tokens.
Use a grant token when your permission to call this operation comes from a new grant that has not yet achieved eventual consistency. For more information, see Grant token and Using a grant token in the Key Management Service Developer Guide.
(string) –
DryRun (boolean) –
Checks if your request will succeed.
DryRunis an optional parameter.To learn more about how to use this parameter, see Testing your permissions in the Key Management Service Developer Guide.
- Return type:
dict
- Returns:
Response Syntax
{ 'KeyId': 'string', 'SharedSecret': b'bytes', 'SharedSecretCiphertextBlob': b'bytes', 'EncapsulationAlgorithm': 'ML_KEM' }
Response Structure
(dict) –
KeyId (string) –
The identifier of the ML-KEM KMS key used to encapsulate the shared secret.
SharedSecret (bytes) –
The plaintext shared secret. It is a 32-byte cryptographically random value that both parties can use directly as key material or pass through a key derivation function to generate multiple keys and nonces. When you use the HTTP API or the Amazon Web Services CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded.
SharedSecretCiphertextBlob (bytes) –
The encapsulated form of the shared secret. Pass this value to the Decapsulate operation to recover the shared secret. When you use the HTTP API or the Amazon Web Services CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded. The length of
SharedSecretCiphertextBlobdepends on the ML-KEM key spec. Before Base64 encoding, the encapsulated shared secret is 768 bytes forML_KEM_512, 1088 bytes forML_KEM_768, and 1568 bytes forML_KEM_1024.EncapsulationAlgorithm (string) –
The key encapsulation algorithm used to generate the shared secret.
Exceptions
KMS.Client.exceptions.NotFoundExceptionKMS.Client.exceptions.DisabledExceptionKMS.Client.exceptions.KeyUnavailableExceptionKMS.Client.exceptions.DependencyTimeoutExceptionKMS.Client.exceptions.InvalidGrantTokenExceptionKMS.Client.exceptions.InvalidKeyUsageExceptionKMS.Client.exceptions.KMSInternalExceptionKMS.Client.exceptions.KMSInvalidStateExceptionKMS.Client.exceptions.DryRunOperationException