decapsulate
async
¶
decapsulate(
key_id: KeyIdType,
shared_secret_ciphertext_blob: CiphertextType,
encapsulation_algorithm: EncapsulationAlgorithmSpec,
*,
config_overrides: Optional[AsyncKMSClientConfig] = None,
grant_tokens: Optional[GrantTokenList] = None,
dry_run: Optional[NullableBooleanType] = None,
) -> DecapsulateResponse
Recovers the shared secret that was encapsulated with the public key of an ML-KEM KMS key. 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 Decapsulate operation is not available in China Regions.
Decapsulate returns the shared secret as a 32-byte value. You can use it directly as key material, or run it through a key derivation function to derive multiple keys and nonces.
Decapsulate returns an InvalidCiphertextException when the length of the SharedSecretCiphertextBlob is inconsistent with the ML-KEM key spec. In all other cases, Decapsulate returns a 32-byte pseudo-random value. This is true even when the SharedSecretCiphertextBlob was created using a different ML-KEM key or altered from its original value. This behavior is a security feature called implicit rejection that helps protect against chosen-ciphertext attacks.
Because a response does not indicate that the ciphertext and key are valid, confirm the two parties derived the same shared secret before using it.
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 KeyId parameter.
Required permissions: kms:Decapsulate (key policy)
Related operations:
Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.
Parameters:
-
key_id(KeyIdType) –Identifies the asymmetric ML-KEM KMS key whose public key was used to produce the encapsulated shared secret. KMS uses the private key in the specified key pair to decapsulate the shared secret.
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-1234567890ab -
Key ARN:
arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab -
Alias name:
alias/ExampleAlias -
Alias 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.
-
-
shared_secret_ciphertext_blob(CiphertextType) –The encapsulated (ciphertext) form of the shared secret to recover. This is the
SharedSecretCiphertextBlobvalue that the Encapsulate operation returns. When you use the HTTP API or the Amazon Web Services CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded. -
encapsulation_algorithm(EncapsulationAlgorithmSpec) –Specifies the key encapsulation algorithm used to recover the shared secret. The only valid value is
ML_KEM. -
grant_tokens(Optional[GrantTokenList], default:None) –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.
-
dry_run(Optional[NullableBooleanType], default:None) –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.
Raises:
-
DependencyTimeoutException–The system timed out while trying to fulfill the request. You can retry the request.
-
DisabledException–The request was rejected because the specified KMS key is not enabled.
-
DryRunOperationException–The request was rejected because the DryRun parameter was specified.
-
InvalidCiphertextException–From the Decrypt or ReEncrypt operation, the request was rejected because the specified ciphertext, or additional authenticated data incorporated into the ciphertext, such as the encryption context, is corrupted, missing, or otherwise invalid.
From the ImportKeyMaterial operation, the request was rejected because KMS could not decrypt the encrypted (wrapped) key material.
From the Decapsulate operation, the request was rejected because the length of the
SharedSecretCiphertextBlobis inconsistent with the specified ML-KEM key spec. -
InvalidGrantTokenException–The request was rejected because the specified grant token is not valid.
-
InvalidKeyUsageException–The request was rejected for one of the following reasons:
-
The
KeyUsagevalue of the KMS key is incompatible with the API operation. -
The encryption algorithm or signing algorithm specified for the operation is incompatible with the type of key material in the KMS key
(KeySpec).
For encrypting, decrypting, re-encrypting, and generating data keys, the
KeyUsagemust beENCRYPT_DECRYPT. For signing and verifying messages, theKeyUsagemust beSIGN_VERIFY. For generating and verifying message authentication codes (MACs), theKeyUsagemust beGENERATE_VERIFY_MAC. For deriving key agreement secrets, theKeyUsagemust beKEY_AGREEMENT. For encapsulating and decapsulating shared secrets, theKeyUsagemust beENCAPSULATE_DECAPSULATE. To find theKeyUsageof a KMS key, use the DescribeKey operation.To find the encryption or signing algorithms supported for a particular KMS key, use the DescribeKey operation.
-
-
KeyUnavailableException–The request was rejected because the specified KMS key was not available. You can retry the request.
-
KMSInternalException–The request was rejected because an internal exception occurred. The request can be retried.
-
KMSInvalidStateException–The request was rejected because the state of the specified resource is not valid for this request.
This exceptions means one of the following:
-
The key state of the KMS key is not compatible with the operation.
To find the key state, use the DescribeKey operation. For more information about which key states are compatible with each KMS operation, see Key states of KMS keys in the Key Management Service Developer Guide .
-
For cryptographic operations on KMS keys in custom key stores, this exception represents a general failure with many possible causes. To identify the cause, see the error message that accompanies the exception.
-
-
NotFoundException–The request was rejected because the specified entity or resource could not be found.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To recover a shared secret from its encapsulated ciphertext Recovers a shared secret from its encapsulated ciphertext (SharedSecretCiphertextBlob) using the private key in an asymmetric ML-KEM KMS key. Your peer calls Encapsulate to generate the shared secret and ciphertext.
>>> await client.decapsulate(key_id='1234abcd-12ab-34cd-56ef-1234567890ab', shared_secret_ciphertext_blob='<binary data>', encapsulation_algorithm='ML_KEM')
Source code in docs_src/capo_kms/_services/async_kms.py
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 | |