AWS Key Management Service

2019/11/25 - AWS Key Management Service - 5 new8 updated api methods

Changes  Update kms client to latest version

GetPublicKey (new) Link ¶

Returns the public key of an asymmetric CMK. Unlike the private key of a asymmetric CMK, which never leaves AWS KMS unencrypted, callers with kms:GetPublicKey permission can download the public key of an asymmetric CMK. You can share the public key to allow others to encrypt messages and verify signatures outside of AWS KMS. For information about symmetric and asymmetric CMKs, see Using Symmetric and Asymmetric CMKs in the AWS Key Management Service Developer Guide.

You do not need to download the public key. Instead, you can use the public key within AWS KMS by calling the Encrypt, ReEncrypt, or Verify operations with the identifier of an asymmetric CMK. When you use the public key within AWS KMS, you benefit from the authentication, authorization, and logging that are part of every AWS KMS operation. You also reduce of risk of encrypting data that cannot be decrypted. These features are not effective outside of AWS KMS. For details, see Special Considerations for Downloading Public Keys.

To help you use the public key safely outside of AWS KMS, GetPublicKey returns important information about the public key in the response, including:

Although AWS KMS cannot enforce these restrictions on external operations, it is crucial that you use this information to prevent the public key from being used improperly. For example, you can prevent a public signing key from being used encrypt data, or prevent a public key from being used with an encryption algorithm that is not supported by AWS KMS. You can also avoid errors, such as using the wrong signing algorithm in a verification operation.

The CMK that you use for this operation must be in a compatible key state. For details, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

See also: AWS API Documentation

Request Syntax

client.get_public_key(
    KeyId='string',
    GrantTokens=[
        'string',
    ]
)
type KeyId:

string

param KeyId:

[REQUIRED]

Identifies the asymmetric CMK that includes the public key.

To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/". To specify a CMK in a different AWS 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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

  • (string) --

rtype:

dict

returns:

Response Syntax

{
    'KeyId': 'string',
    'PublicKey': b'bytes',
    'CustomerMasterKeySpec': 'RSA_2048'|'RSA_3072'|'RSA_4096'|'ECC_NIST_P256'|'ECC_NIST_P384'|'ECC_NIST_P521'|'ECC_SECG_P256K1'|'SYMMETRIC_DEFAULT',
    'KeyUsage': 'SIGN_VERIFY'|'ENCRYPT_DECRYPT',
    'EncryptionAlgorithms': [
        'SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256',
    ],
    'SigningAlgorithms': [
        'RSASSA_PSS_SHA_256'|'RSASSA_PSS_SHA_384'|'RSASSA_PSS_SHA_512'|'RSASSA_PKCS1_V1_5_SHA_256'|'RSASSA_PKCS1_V1_5_SHA_384'|'RSASSA_PKCS1_V1_5_SHA_512'|'ECDSA_SHA_256'|'ECDSA_SHA_384'|'ECDSA_SHA_512',
    ]
}

Response Structure

  • (dict) --

    • KeyId (string) --

      The identifier of the asymmetric CMK from which the public key was downloaded.

    • PublicKey (bytes) --

      The exported public key.

      This value is returned as a binary Distinguished Encoding Rules (DER)-encoded object. To decode it, use an ASN.1 parsing tool, such as OpenSSL asn1parse.

    • CustomerMasterKeySpec (string) --

      The type of the of the public key that was downloaded.

    • KeyUsage (string) --

      The permitted use of the public key. Valid values are ENCRYPT_DECRYPT or SIGN_VERIFY.

      This information is critical. If a public key with SIGN_VERIFY key usage encrypts data outside of AWS KMS, the ciphertext cannot be decrypted.

    • EncryptionAlgorithms (list) --

      The encryption algorithms that AWS KMS supports for this key.

      This information is critical. If a public key encrypts data outside of AWS KMS by using an unsupported encryption algorithm, the ciphertext cannot be decrypted.

      This field appears in the response only when the KeyUsage of the public key is ENCRYPT_DECRYPT.

      • (string) --

    • SigningAlgorithms (list) --

      The signing algorithms that AWS KMS supports for this key.

      This field appears in the response only when the KeyUsage of the public key is SIGN_VERIFY.

      • (string) --

GenerateDataKeyPair (new) Link ¶

Generates a unique asymmetric data key pair. The GenerateDataKeyPair operation returns a plaintext public key, a plaintext private key, and a copy of the private key that is encrypted under the symmetric CMK you specify. You can use the data key pair to perform asymmetric cryptography outside of AWS KMS.

GenerateDataKeyPair returns a unique data key pair for each request. The bytes in the keys are not related to the caller or the CMK that is used to encrypt the private key.

You can use the public key that GenerateDataKeyPair returns to encrypt data or verify a signature outside of AWS KMS. Then, store the encrypted private key with the data. When you are ready to decrypt data or sign a message, you can use the Decrypt operation to decrypt the encrypted private key.

To generate a data key pair, you must specify a symmetric customer master key (CMK) to encrypt the private key in a data key pair. You cannot use an asymmetric CMK. To get the type of your CMK, use the DescribeKey operation.

If you are using the data key pair to encrypt data, or for any operation where you don't immediately need a private key, consider using the GenerateDataKeyPairWithoutPlaintext operation. GenerateDataKeyPairWithoutPlaintext returns a plaintext public key and an encrypted private key, but omits the plaintext private key that you need only to decrypt ciphertext or sign a message. Later, when you need to decrypt the data or sign a message, use the Decrypt operation to decrypt the encrypted private key in the data key pair.

You can use the optional encryption context to add additional security to the encryption operation. If you specify an EncryptionContext, you must specify the same encryption context (a case-sensitive exact match) when decrypting the encrypted data key. Otherwise, the request to decrypt fails with an InvalidCiphertextException. For more information, see Encryption Context in the AWS Key Management Service Developer Guide.

The CMK that you use for this operation must be in a compatible key state. For details, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

See also: AWS API Documentation

Request Syntax

client.generate_data_key_pair(
    EncryptionContext={
        'string': 'string'
    },
    KeyId='string',
    KeyPairSpec='RSA_2048'|'RSA_3072'|'RSA_4096'|'ECC_NIST_P256'|'ECC_NIST_P384'|'ECC_NIST_P521'|'ECC_SECG_P256K1',
    GrantTokens=[
        'string',
    ]
)
type EncryptionContext:

dict

param EncryptionContext:

Specifies the encryption context that will be used when encrypting the private key in the data key pair.

An encryption context is a collection of non-secret key-value pairs that represents additional authenticated data. When you use an encryption context to encrypt data, you must specify the same (an exact case-sensitive match) encryption context to decrypt the data. An encryption context is optional when encrypting with a symmetric CMK, but it is highly recommended.

For more information, see Encryption Context in the AWS Key Management Service Developer Guide.

  • (string) --

    • (string) --

type KeyId:

string

param KeyId:

[REQUIRED]

Specifies the symmetric CMK that encrypts the private key in the data key pair. You cannot specify an asymmetric CMKs.

To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/". To specify a CMK in a different AWS 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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

type KeyPairSpec:

string

param KeyPairSpec:

[REQUIRED]

Determines the type of data key pair that is generated.

The AWS KMS rule that restricts the use of asymmetric RSA CMKs to encrypt and decrypt or to sign and verify (but not both), and the rule that permits you to use ECC CMKs only to sign and verify, are not effective outside of AWS KMS.

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

  • (string) --

rtype:

dict

returns:

Response Syntax

{
    'PrivateKeyCiphertextBlob': b'bytes',
    'PrivateKeyPlaintext': b'bytes',
    'PublicKey': b'bytes',
    'KeyId': 'string',
    'KeyPairSpec': 'RSA_2048'|'RSA_3072'|'RSA_4096'|'ECC_NIST_P256'|'ECC_NIST_P384'|'ECC_NIST_P521'|'ECC_SECG_P256K1'
}

Response Structure

  • (dict) --

    • PrivateKeyCiphertextBlob (bytes) --

      The encrypted copy of the private key. When you use the HTTP API or the AWS CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded.

    • PrivateKeyPlaintext (bytes) --

      The plaintext copy of the private key. When you use the HTTP API or the AWS CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded.

    • PublicKey (bytes) --

      The public key (in plaintext).

    • KeyId (string) --

      The identifier of the CMK that encrypted the private key.

    • KeyPairSpec (string) --

      The type of data key pair that was generated.

Verify (new) Link ¶

Verifies a digital signature that was generated by the Sign operation. This operation requires an asymmetric CMK with a KeyUsage value of SIGN_VERIFY.

Verification confirms that an authorized user signed the message with the specified key and signing algorithm, and the message hasn't changed since it was signed. A digital signature is generated by using the private key in an asymmetric CMK. The signature is verified by using the public key in the same asymmetric CMK. For information about symmetric and asymmetric CMKs, see Using Symmetric and Asymmetric CMKs in the AWS Key Management Service Developer Guide.

To verify a digital signature, you can use the Verify operation. Specify the same asymmetric CMK that was used by the Sign operation to generate the digital signature.

You can also verify the digital signature by using the public key of the CMK outside of AWS KMS. Use the GetPublicKey operation to download the public key in the asymmetric CMK and then use the public key to verify the signature outside of AWS KMS.

The advantage of using the Verify operation is that it is performed within AWS KMS. As a result, it's easy to call, the operation is performed within the FIPS boundary, it is logged in AWS CloudTrail, and you can use key policy and IAM policy to determine who is authorized to use the CMK to verify signatures.

The CMK that you use for this operation must be in a compatible key state. For details, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

See also: AWS API Documentation

Request Syntax

client.verify(
    KeyId='string',
    Message=b'bytes',
    MessageType='RAW'|'DIGEST',
    Signature=b'bytes',
    SigningAlgorithm='RSASSA_PSS_SHA_256'|'RSASSA_PSS_SHA_384'|'RSASSA_PSS_SHA_512'|'RSASSA_PKCS1_V1_5_SHA_256'|'RSASSA_PKCS1_V1_5_SHA_384'|'RSASSA_PKCS1_V1_5_SHA_512'|'ECDSA_SHA_256'|'ECDSA_SHA_384'|'ECDSA_SHA_512',
    GrantTokens=[
        'string',
    ]
)
type KeyId:

string

param KeyId:

[REQUIRED]

Identifies the asymmetric CMK that will be used to verify the signature. This must be the same CMK that was used to generate the signature. If you specify a different CMK, the value of the SignatureValid field in the response will be False.

To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/". To specify a CMK in a different AWS 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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

type Message:

bytes

param Message:

[REQUIRED]

Specifies the message that was signed, or a hash digest of that message. Messages can be 0-4096 bytes. To verify a larger message, provide a hash digest of the message.

If the digest of the message specified here is different from the message digest that was signed, the SignatureValid value in the response will be False.

type MessageType:

string

param MessageType:

Tells AWS KMS whether the value of the Message parameter is a message or message digest. To indicate a message, enter RAW. To indicate a message digest, enter DIGEST.

type Signature:

bytes

param Signature:

[REQUIRED]

The signature that the Sign operation generated.

type SigningAlgorithm:

string

param SigningAlgorithm:

[REQUIRED]

The signing algorithm that was used to sign the message. If you submit a different algorithm, the value of the SignatureValid field in the response will be False.

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

  • (string) --

rtype:

dict

returns:

Response Syntax

{
    'KeyId': 'string',
    'SignatureValid': True|False,
    'SigningAlgorithm': 'RSASSA_PSS_SHA_256'|'RSASSA_PSS_SHA_384'|'RSASSA_PSS_SHA_512'|'RSASSA_PKCS1_V1_5_SHA_256'|'RSASSA_PKCS1_V1_5_SHA_384'|'RSASSA_PKCS1_V1_5_SHA_512'|'ECDSA_SHA_256'|'ECDSA_SHA_384'|'ECDSA_SHA_512'
}

Response Structure

  • (dict) --

    • KeyId (string) --

      The unique identifier for the asymmetric CMK that was used to verify the signature.

    • SignatureValid (boolean) --

      A Boolean value that indicates whether the signature was verified. A value of True indicates that the Signature was produced by signing the Message with the specified KeyID and SigningAlgorithm. A value of False indicates that the message, the algorithm, or the key changed since the message was signed.

    • SigningAlgorithm (string) --

      The signing algorithm that was used to verify the signature.

Sign (new) Link ¶

Creates a digital signature for a message or message digest by using the private key in an asymmetric CMK. To verify the signature, use the Verify operation, or use the public key in the same asymmetric CMK outside of AWS KMS. For information about symmetric and asymmetric CMKs, see Using Symmetric and Asymmetric CMKs in the AWS Key Management Service Developer Guide.

Digital signatures are generated and verified by using asymmetric key pair, such as an RSA or ECC pair that is represented by an asymmetric customer master key (CMK). The key owner (or an authorized user) uses their private key to sign a message. Anyone with the public key can verify that the message was signed with that particular private key and that the message hasn't changed since it was signed.

To use the Sign operation, provide the following information:

  • Use the KeyId parameter to identify an asymmetric CMK with a KeyUsage value of SIGN_VERIFY. To get the KeyUsage value of a CMK, use the DescribeKey operation. The caller must have kms:Sign permission on the CMK.

  • Use the Message parameter to specify the message or message digest to sign. You can submit messages of up to 4096 bytes. To sign a larger message, generate a hash digest of the message, and then provide the hash digest in the Message parameter. To indicate whether the message is a full message or a digest, use the MessageType parameter.

  • Choose a signing algorithm that is compatible with the CMK.

To verify the signature that this operation generates, use the Verify operation. Or use the GetPublicKey operation to download the public key and then use the public key to verify the signature outside of AWS KMS.

The CMK that you use for this operation must be in a compatible key state. For details, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

See also: AWS API Documentation

Request Syntax

client.sign(
    KeyId='string',
    Message=b'bytes',
    MessageType='RAW'|'DIGEST',
    GrantTokens=[
        'string',
    ],
    SigningAlgorithm='RSASSA_PSS_SHA_256'|'RSASSA_PSS_SHA_384'|'RSASSA_PSS_SHA_512'|'RSASSA_PKCS1_V1_5_SHA_256'|'RSASSA_PKCS1_V1_5_SHA_384'|'RSASSA_PKCS1_V1_5_SHA_512'|'ECDSA_SHA_256'|'ECDSA_SHA_384'|'ECDSA_SHA_512'
)
type KeyId:

string

param KeyId:

[REQUIRED]

Identifies an asymmetric CMK. AWS KMS uses the private key in the asymmetric CMK to sign the message. The KeyUsage type of the CMK must be SIGN_VERIFY. To find the KeyUsage of a CMK, use the DescribeKey operation.

To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/". To specify a CMK in a different AWS 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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

type Message:

bytes

param Message:

[REQUIRED]

Specifies the message or message digest to sign. Messages can be 0-4096 bytes. To sign a larger message, provide the message digest.

If you provide a message, AWS KMS generates a hash digest of the message and then signs it.

type MessageType:

string

param MessageType:

Tells AWS KMS whether the value of the Message parameter is a message or message digest. To indicate a message, enter RAW. To indicate a message digest, enter DIGEST.

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

  • (string) --

type SigningAlgorithm:

string

param SigningAlgorithm:

[REQUIRED]

Specifies the signing algorithm to use when signing the message.

Choose an algorithm that is compatible with the type and size of the specified asymmetric CMK.

rtype:

dict

returns:

Response Syntax

{
    'KeyId': 'string',
    'Signature': b'bytes',
    'SigningAlgorithm': 'RSASSA_PSS_SHA_256'|'RSASSA_PSS_SHA_384'|'RSASSA_PSS_SHA_512'|'RSASSA_PKCS1_V1_5_SHA_256'|'RSASSA_PKCS1_V1_5_SHA_384'|'RSASSA_PKCS1_V1_5_SHA_512'|'ECDSA_SHA_256'|'ECDSA_SHA_384'|'ECDSA_SHA_512'
}

Response Structure

  • (dict) --

    • KeyId (string) --

      The Amazon Resource Name (ARN) of the asymmetric CMK that was used to sign the message.

    • Signature (bytes) --

      The cryptographic signature that was generated for the message.

    • SigningAlgorithm (string) --

      The signing algorithm that was used to sign the message.

GenerateDataKeyPairWithoutPlaintext (new) Link ¶

Generates a unique asymmetric data key pair. The GenerateDataKeyPairWithoutPlaintext operation returns a plaintext public key and a copy of the private key that is encrypted under the symmetric CMK you specify. Unlike GenerateDataKeyPair, this operation does not return a plaintext private key.

To generate a data key pair, you must specify a symmetric customer master key (CMK) to encrypt the private key in the data key pair. You cannot use an asymmetric CMK. To get the type of your CMK, use the KeySpec field in the DescribeKey response.

You can use the public key that GenerateDataKeyPairWithoutPlaintext returns to encrypt data or verify a signature outside of AWS KMS. Then, store the encrypted private key with the data. When you are ready to decrypt data or sign a message, you can use the Decrypt operation to decrypt the encrypted private key.

GenerateDataKeyPairWithoutPlaintext returns a unique data key pair for each request. The bytes in the key are not related to the caller or CMK that is used to encrypt the private key.

You can use the optional encryption context to add additional security to the encryption operation. If you specify an EncryptionContext, you must specify the same encryption context (a case-sensitive exact match) when decrypting the encrypted data key. Otherwise, the request to decrypt fails with an InvalidCiphertextException. For more information, see Encryption Context in the AWS Key Management Service Developer Guide.

The CMK that you use for this operation must be in a compatible key state. For details, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

See also: AWS API Documentation

Request Syntax

client.generate_data_key_pair_without_plaintext(
    EncryptionContext={
        'string': 'string'
    },
    KeyId='string',
    KeyPairSpec='RSA_2048'|'RSA_3072'|'RSA_4096'|'ECC_NIST_P256'|'ECC_NIST_P384'|'ECC_NIST_P521'|'ECC_SECG_P256K1',
    GrantTokens=[
        'string',
    ]
)
type EncryptionContext:

dict

param EncryptionContext:

Specifies the encryption context that will be used when encrypting the private key in the data key pair.

An encryption context is a collection of non-secret key-value pairs that represents additional authenticated data. When you use an encryption context to encrypt data, you must specify the same (an exact case-sensitive match) encryption context to decrypt the data. An encryption context is optional when encrypting with a symmetric CMK, but it is highly recommended.

For more information, see Encryption Context in the AWS Key Management Service Developer Guide.

  • (string) --

    • (string) --

type KeyId:

string

param KeyId:

[REQUIRED]

Specifies the CMK that encrypts the private key in the data key pair. You must specify a symmetric CMK. You cannot use an asymmetric CMK.

To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/".

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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

type KeyPairSpec:

string

param KeyPairSpec:

[REQUIRED]

Determines the type of data key pair that is generated.

The AWS KMS rule that restricts the use of asymmetric RSA CMKs to encrypt and decrypt or to sign and verify (but not both), and the rule that permits you to use ECC CMKs only to sign and verify, are not effective outside of AWS KMS.

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

  • (string) --

rtype:

dict

returns:

Response Syntax

{
    'PrivateKeyCiphertextBlob': b'bytes',
    'PublicKey': b'bytes',
    'KeyId': 'string',
    'KeyPairSpec': 'RSA_2048'|'RSA_3072'|'RSA_4096'|'ECC_NIST_P256'|'ECC_NIST_P384'|'ECC_NIST_P521'|'ECC_SECG_P256K1'
}

Response Structure

  • (dict) --

    • PrivateKeyCiphertextBlob (bytes) --

      The encrypted copy of the private key. When you use the HTTP API or the AWS CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded.

    • PublicKey (bytes) --

      The public key (in plaintext).

    • KeyId (string) --

      Specifies the CMK that encrypted the private key in the data key pair. You must specify a symmetric CMK. You cannot use an asymmetric CMK.

      To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/".

      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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

    • KeyPairSpec (string) --

      The type of data key pair that was generated.

CreateGrant (updated) Link ¶
Changes (request)
{'Operations': {'GenerateDataKeyPair',
                'GenerateDataKeyPairWithoutPlaintext',
                'GetPublicKey',
                'Sign',
                'Verify'}}

Adds a grant to a customer master key (CMK). The grant allows the grantee principal to use the CMK when the conditions specified in the grant are met. When setting permissions, grants are an alternative to key policies.

To create a grant that allows a cryptographic operation only when the request includes a particular encryption context, use the Constraints parameter. For details, see GrantConstraints.

You can create grants on symmetric and asymmetric CMKs. However, if the grant allows an operation that the CMK does not support, CreateGrant fails with a ValidationException.

  • Grants for symmetric CMKs cannot allow operations that are not supported for symmetric CMKs, including Sign, Verify, and GetPublicKey. (There are limited exceptions to this rule for legacy operations, but you should not create a grant for an operation that AWS KMS does not support.)

  • Grants for asymmetric CMKs cannot allow operations that are not supported for asymmetric CMKs, including operations that generate data keys or data key pairs, or operations related to automatic key rotation, imported key material, or CMKs in custom key stores.

  • Grants for asymmetric CMKs with a KeyUsage of ENCRYPT_DECRYPT cannot allow the Sign or Verify operations. Grants for asymmetric CMKs with a KeyUsage of SIGN_VERIFY cannot allow the Encrypt or Decrypt operations.

  • Grants for asymmetric CMKs cannot include an encryption context grant constraint. An encryption context is not supported on asymmetric CMKs.

For information about symmetric and asymmetric CMKs, see Using Symmetric and Asymmetric CMKs in the AWS Key Management Service Developer Guide.

To perform this operation on a CMK in a different AWS account, specify the key ARN in the value of the KeyId parameter. For more information about grants, see Grants in the AWS Key Management Service Developer Guide .

The CMK that you use for this operation must be in a compatible key state. For details, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

See also: AWS API Documentation

Request Syntax

client.create_grant(
    KeyId='string',
    GranteePrincipal='string',
    RetiringPrincipal='string',
    Operations=[
        'Decrypt'|'Encrypt'|'GenerateDataKey'|'GenerateDataKeyWithoutPlaintext'|'ReEncryptFrom'|'ReEncryptTo'|'Sign'|'Verify'|'GetPublicKey'|'CreateGrant'|'RetireGrant'|'DescribeKey'|'GenerateDataKeyPair'|'GenerateDataKeyPairWithoutPlaintext',
    ],
    Constraints={
        'EncryptionContextSubset': {
            'string': 'string'
        },
        'EncryptionContextEquals': {
            'string': 'string'
        }
    },
    GrantTokens=[
        'string',
    ],
    Name='string'
)
type KeyId:

string

param KeyId:

[REQUIRED]

The unique identifier for the customer master key (CMK) that the grant applies to.

Specify the key ID or the Amazon Resource Name (ARN) of the CMK. To specify a CMK in a different AWS account, you must use the key 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

To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey.

type GranteePrincipal:

string

param GranteePrincipal:

[REQUIRED]

The principal that is given permission to perform the operations that the grant permits.

To specify the principal, use the Amazon Resource Name (ARN) of an AWS principal. Valid AWS principals include AWS accounts (root), IAM users, IAM roles, federated users, and assumed role users. For examples of the ARN syntax to use for specifying a principal, see AWS Identity and Access Management (IAM) in the Example ARNs section of the AWS General Reference.

type RetiringPrincipal:

string

param RetiringPrincipal:

The principal that is given permission to retire the grant by using RetireGrant operation.

To specify the principal, use the Amazon Resource Name (ARN) of an AWS principal. Valid AWS principals include AWS accounts (root), IAM users, federated users, and assumed role users. For examples of the ARN syntax to use for specifying a principal, see AWS Identity and Access Management (IAM) in the Example ARNs section of the AWS General Reference.

type Operations:

list

param Operations:

[REQUIRED]

A list of operations that the grant permits.

  • (string) --

type Constraints:

dict

param Constraints:

Allows a cryptographic operation only when the encryption context matches or includes the encryption context specified in this structure. For more information about encryption context, see Encryption Context in the AWS Key Management Service Developer Guide .

  • EncryptionContextSubset (dict) --

    A list of key-value pairs that must be included in the encryption context of the cryptographic operation request. The grant allows the cryptographic operation only when the encryption context in the request includes the key-value pairs specified in this constraint, although it can include additional key-value pairs.

    • (string) --

      • (string) --

  • EncryptionContextEquals (dict) --

    A list of key-value pairs that must match the encryption context in the cryptographic operation request. The grant allows the operation only when the encryption context in the request is the same as the encryption context specified in this constraint.

    • (string) --

      • (string) --

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

  • (string) --

type Name:

string

param Name:

A friendly name for identifying the grant. Use this value to prevent the unintended creation of duplicate grants when retrying this request.

When this value is absent, all CreateGrant requests result in a new grant with a unique GrantId even if all the supplied parameters are identical. This can result in unintended duplicates when you retry the CreateGrant request.

When this value is present, you can retry a CreateGrant request with identical parameters; if the grant already exists, the original GrantId is returned without creating a new grant. Note that the returned grant token is unique with every CreateGrant request, even when a duplicate GrantId is returned. All grant tokens obtained in this way can be used interchangeably.

rtype:

dict

returns:

Response Syntax

{
    'GrantToken': 'string',
    'GrantId': 'string'
}

Response Structure

  • (dict) --

    • GrantToken (string) --

      The grant token.

      For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

    • GrantId (string) --

      The unique identifier for the grant.

      You can use the GrantId in a subsequent RetireGrant or RevokeGrant operation.

CreateKey (updated) Link ¶
Changes (request, response)
Request
{'CustomerMasterKeySpec': 'RSA_2048 | RSA_3072 | RSA_4096 | ECC_NIST_P256 | '
                          'ECC_NIST_P384 | ECC_NIST_P521 | ECC_SECG_P256K1 | '
                          'SYMMETRIC_DEFAULT',
 'KeyUsage': {'SIGN_VERIFY'}}
Response
{'KeyMetadata': {'CustomerMasterKeySpec': 'RSA_2048 | RSA_3072 | RSA_4096 | '
                                          'ECC_NIST_P256 | ECC_NIST_P384 | '
                                          'ECC_NIST_P521 | ECC_SECG_P256K1 | '
                                          'SYMMETRIC_DEFAULT',
                 'EncryptionAlgorithms': ['SYMMETRIC_DEFAULT | '
                                          'RSAES_OAEP_SHA_1 | '
                                          'RSAES_OAEP_SHA_256'],
                 'KeyUsage': {'SIGN_VERIFY'},
                 'SigningAlgorithms': ['RSASSA_PSS_SHA_256 | '
                                       'RSASSA_PSS_SHA_384 | '
                                       'RSASSA_PSS_SHA_512 | '
                                       'RSASSA_PKCS1_V1_5_SHA_256 | '
                                       'RSASSA_PKCS1_V1_5_SHA_384 | '
                                       'RSASSA_PKCS1_V1_5_SHA_512 | '
                                       'ECDSA_SHA_256 | ECDSA_SHA_384 | '
                                       'ECDSA_SHA_512']}}

Creates a unique customer managed customer master key (CMK) in your AWS account and Region. You cannot use this operation to create a CMK in a different AWS account.

You can use the CreateKey operation to create symmetric or asymmetric CMKs.

  • Symmetric CMKs contain a 256-bit symmetric key that never leaves AWS KMS unencrypted. To use the CMK, you must call AWS KMS. You can use a symmetric CMK to encrypt and decrypt small amounts of data, but they are typically used to generate data keys or data key pairs. For details, see GenerateDataKey and GenerateDataKeyPair.

  • Asymmetric CMKs can contain an RSA key pair or an Elliptic Curve (ECC) key pair. The private key in an asymmetric CMK never leaves AWS KMS unencrypted. However, you can use the GetPublicKey operation to download the public key so it can be used outside of AWS KMS. CMKs with RSA key pairs can be used to encrypt or decrypt data or sign and verify messages (but not both). CMKs with ECC key pairs can be used only to sign and verify messages.

For information about symmetric and asymmetric CMKs, see Using Symmetric and Asymmetric CMKs in the AWS Key Management Service Developer Guide.

To create different types of CMKs, use the following guidance:

Asymmetric CMKs

To create an asymmetric CMK, use the CustomerMasterKeySpec parameter to specify the type of key material in the CMK. Then, use the KeyUsage parameter to determine whether the CMK will be used to encrypt and decrypt or sign and verify. You can't change these properties after the CMK is created.

Symmetric CMKs

When creating a symmetric CMK, you don't need to specify the CustomerMasterKeySpec or KeyUsage parameters. The default value for CustomerMasterKeySpec, SYMMETRIC_DEFAULT, and the default value for KeyUsage, ENCRYPT_DECRYPT, are the only valid values for symmetric CMKs.

Imported Key Material

To import your own key material, begin by creating a symmetric CMK with no key material. To do this, use the Origin parameter of CreateKey with a value of EXTERNAL. Next, use GetParametersForImport operation to get a public key and import token, and use the public key to encrypt your key material. Then, use ImportKeyMaterial with your import token to import the key material. For step-by-step instructions, see Importing Key Material in the AWS Key Management Service Developer Guide . You cannot import the key material into an asymmetric CMK.

Custom Key Stores

To create a symmetric CMK in a custom key store, use the CustomKeyStoreId parameter to specify the custom key store. You must also use the Origin parameter with a value of AWS_CLOUDHSM. The AWS CloudHSM cluster that is associated with the custom key store must have at least two active HSMs in different Availability Zones in the AWS Region.

You cannot create an asymmetric CMK in a custom key store. For information about custom key stores in AWS KMS see Using Custom Key Stores in the AWS Key Management Service Developer Guide .

See also: AWS API Documentation

Request Syntax

client.create_key(
    Policy='string',
    Description='string',
    KeyUsage='SIGN_VERIFY'|'ENCRYPT_DECRYPT',
    CustomerMasterKeySpec='RSA_2048'|'RSA_3072'|'RSA_4096'|'ECC_NIST_P256'|'ECC_NIST_P384'|'ECC_NIST_P521'|'ECC_SECG_P256K1'|'SYMMETRIC_DEFAULT',
    Origin='AWS_KMS'|'EXTERNAL'|'AWS_CLOUDHSM',
    CustomKeyStoreId='string',
    BypassPolicyLockoutSafetyCheck=True|False,
    Tags=[
        {
            'TagKey': 'string',
            'TagValue': 'string'
        },
    ]
)
type Policy:

string

param Policy:

The key policy to attach to the CMK.

If you provide a key policy, it must meet the following criteria:

  • If you don't set BypassPolicyLockoutSafetyCheck to true, the key policy must allow the principal that is making the CreateKey request to make a subsequent PutKeyPolicy request on the CMK. This reduces the risk that the CMK becomes unmanageable. For more information, refer to the scenario in the Default Key Policy section of the AWS Key Management Service Developer Guide .

  • Each statement in the key policy must contain one or more principals. The principals in the key policy must exist and be visible to AWS KMS. When you create a new AWS principal (for example, an IAM user or role), you might need to enforce a delay before including the new principal in a key policy because the new principal might not be immediately visible to AWS KMS. For more information, see Changes that I make are not always immediately visible in the AWS Identity and Access Management User Guide.

If you do not provide a key policy, AWS KMS attaches a default key policy to the CMK. For more information, see Default Key Policy in the AWS Key Management Service Developer Guide.

The key policy size limit is 32 kilobytes (32768 bytes).

type Description:

string

param Description:

A description of the CMK.

Use a description that helps you decide whether the CMK is appropriate for a task.

type KeyUsage:

string

param KeyUsage:

Determines the cryptographic operations for which you can use the CMK. The default value is ENCRYPT_DECRYPT. This parameter is required only for asymmetric CMKs. You can't change the KeyUsage value after the CMK is created.

Select only one valid value.

  • For symmetric CMKs, omit the parameter or specify ENCRYPT_DECRYPT.

  • For asymmetric CMKs with RSA key material, specify ENCRYPT_DECRYPT or SIGN_VERIFY.

  • For asymmetric CMKs with ECC key material, specify SIGN_VERIFY.

type CustomerMasterKeySpec:

string

param CustomerMasterKeySpec:

Specifies the type of CMK to create. The CustomerMasterKeySpec determines whether the CMK contains a symmetric key or an asymmetric key pair. It also determines the encryption algorithms or signing algorithms that the CMK supports. You can't change the CustomerMasterKeySpec after the CMK is created. To further restrict the algorithms that can be used with the CMK, use its key policy or IAM policy.

For help with choosing a key spec for your CMK, see Selecting a Customer Master Key Spec in the AWS Key Management Service Developer Guide.

The default value, SYMMETRIC_DEFAULT, creates a CMK with a 256-bit symmetric key.

AWS KMS supports the following key specs for CMKs:

  • Symmetric key (default)

    • SYMMETRIC_DEFAULT (AES-256-GCM)

  • Asymmetric RSA key pairs

    • RSA_2048

    • RSA_3072

    • RSA_4096

  • Asymmetric NIST-recommended elliptic curve key pairs

    • ECC_NIST_P256 (secp256r1)

    • ECC_NIST_P384 (secp384r1)

    • ECC_NIST_P521 (secp521r1)

  • Other asymmetric elliptic curve key pairs

    • ECC_SECG_P256K1 (secp256k1), commonly used for cryptocurrencies.

type Origin:

string

param Origin:

The source of the key material for the CMK. You cannot change the origin after you create the CMK. The default is AWS_KMS, which means AWS KMS creates the key material.

When the parameter value is EXTERNAL, AWS KMS creates a CMK without key material so that you can import key material from your existing key management infrastructure. For more information about importing key material into AWS KMS, see Importing Key Material in the AWS Key Management Service Developer Guide. This value is valid only for symmetric CMKs.

When the parameter value is AWS_CLOUDHSM, AWS KMS creates the CMK in an AWS KMS custom key store and creates its key material in the associated AWS CloudHSM cluster. You must also use the CustomKeyStoreId parameter to identify the custom key store. This value is valid only for symmetric CMKs.

type CustomKeyStoreId:

string

param CustomKeyStoreId:

Creates the CMK in the specified custom key store and the key material in its associated AWS CloudHSM cluster. To create a CMK in a custom key store, you must also specify the Origin parameter with a value of AWS_CLOUDHSM. The AWS CloudHSM cluster that is associated with the custom key store must have at least two active HSMs, each in a different Availability Zone in the Region.

This parameter is valid only for symmetric CMKs. You cannot create an asymmetric CMK in a custom key store.

To find the ID of a custom key store, use the DescribeCustomKeyStores operation.

The response includes the custom key store ID and the ID of the AWS CloudHSM cluster.

This operation is part of the Custom Key Store feature feature in AWS KMS, which combines the convenience and extensive integration of AWS KMS with the isolation and control of a single-tenant key store.

type BypassPolicyLockoutSafetyCheck:

boolean

param BypassPolicyLockoutSafetyCheck:

A flag to indicate whether to bypass the key policy lockout safety check.

Use this parameter only when you include a policy in the request and you intend to prevent the principal that is making the request from making a subsequent PutKeyPolicy request on the CMK.

The default value is false.

type Tags:

list

param Tags:

One or more tags. Each tag consists of a tag key and a tag value. Both the tag key and the tag value are required, but the tag value can be an empty (null) string.

When you add tags to an AWS resource, AWS generates a cost allocation report with usage and costs aggregated by tags. For information about adding, changing, deleting and listing tags for CMKs, see Tagging Keys.

Use this parameter to tag the CMK when it is created. To add tags to an existing CMK, use the TagResource operation.

  • (dict) --

    A key-value pair. A tag consists of a tag key and a tag value. Tag keys and tag values are both required, but tag values can be empty (null) strings.

    For information about the rules that apply to tag keys and tag values, see User-Defined Tag Restrictions in the AWS Billing and Cost Management User Guide.

    • TagKey (string) -- [REQUIRED]

      The key of the tag.

    • TagValue (string) -- [REQUIRED]

      The value of the tag.

rtype:

dict

returns:

Response Syntax

{
    'KeyMetadata': {
        'AWSAccountId': 'string',
        'KeyId': 'string',
        'Arn': 'string',
        'CreationDate': datetime(2015, 1, 1),
        'Enabled': True|False,
        'Description': 'string',
        'KeyUsage': 'SIGN_VERIFY'|'ENCRYPT_DECRYPT',
        'KeyState': 'Enabled'|'Disabled'|'PendingDeletion'|'PendingImport'|'Unavailable',
        'DeletionDate': datetime(2015, 1, 1),
        'ValidTo': datetime(2015, 1, 1),
        'Origin': 'AWS_KMS'|'EXTERNAL'|'AWS_CLOUDHSM',
        'CustomKeyStoreId': 'string',
        'CloudHsmClusterId': 'string',
        'ExpirationModel': 'KEY_MATERIAL_EXPIRES'|'KEY_MATERIAL_DOES_NOT_EXPIRE',
        'KeyManager': 'AWS'|'CUSTOMER',
        'CustomerMasterKeySpec': 'RSA_2048'|'RSA_3072'|'RSA_4096'|'ECC_NIST_P256'|'ECC_NIST_P384'|'ECC_NIST_P521'|'ECC_SECG_P256K1'|'SYMMETRIC_DEFAULT',
        'EncryptionAlgorithms': [
            'SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256',
        ],
        'SigningAlgorithms': [
            'RSASSA_PSS_SHA_256'|'RSASSA_PSS_SHA_384'|'RSASSA_PSS_SHA_512'|'RSASSA_PKCS1_V1_5_SHA_256'|'RSASSA_PKCS1_V1_5_SHA_384'|'RSASSA_PKCS1_V1_5_SHA_512'|'ECDSA_SHA_256'|'ECDSA_SHA_384'|'ECDSA_SHA_512',
        ]
    }
}

Response Structure

  • (dict) --

    • KeyMetadata (dict) --

      Metadata associated with the CMK.

      • AWSAccountId (string) --

        The twelve-digit account ID of the AWS account that owns the CMK.

      • KeyId (string) --

        The globally unique identifier for the CMK.

      • Arn (string) --

        The Amazon Resource Name (ARN) of the CMK. For examples, see AWS Key Management Service (AWS KMS) in the Example ARNs section of the AWS General Reference.

      • CreationDate (datetime) --

        The date and time when the CMK was created.

      • Enabled (boolean) --

        Specifies whether the CMK is enabled. When KeyState is Enabled this value is true, otherwise it is false.

      • Description (string) --

        The description of the CMK.

      • KeyUsage (string) --

        The cryptographic operations for which you can use the CMK.

      • KeyState (string) --

        The state of the CMK.

        For more information about how key state affects the use of a CMK, see How Key State Affects the Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

      • DeletionDate (datetime) --

        The date and time after which AWS KMS deletes the CMK. This value is present only when KeyState is PendingDeletion.

      • ValidTo (datetime) --

        The time at which the imported key material expires. When the key material expires, AWS KMS deletes the key material and the CMK becomes unusable. This value is present only for CMKs whose Origin is EXTERNAL and whose ExpirationModel is KEY_MATERIAL_EXPIRES, otherwise this value is omitted.

      • Origin (string) --

        The source of the CMK's key material. When this value is AWS_KMS, AWS KMS created the key material. When this value is EXTERNAL, the key material was imported from your existing key management infrastructure or the CMK lacks key material. When this value is AWS_CLOUDHSM, the key material was created in the AWS CloudHSM cluster associated with a custom key store.

      • CustomKeyStoreId (string) --

        A unique identifier for the custom key store that contains the CMK. This value is present only when the CMK is created in a custom key store.

      • CloudHsmClusterId (string) --

        The cluster ID of the AWS CloudHSM cluster that contains the key material for the CMK. When you create a CMK in a custom key store, AWS KMS creates the key material for the CMK in the associated AWS CloudHSM cluster. This value is present only when the CMK is created in a custom key store.

      • ExpirationModel (string) --

        Specifies whether the CMK's key material expires. This value is present only when Origin is EXTERNAL, otherwise this value is omitted.

      • KeyManager (string) --

        The manager of the CMK. CMKs in your AWS account are either customer managed or AWS managed. For more information about the difference, see Customer Master Keys in the AWS Key Management Service Developer Guide.

      • CustomerMasterKeySpec (string) --

        Describes the type of key material in the CMK.

      • EncryptionAlgorithms (list) --

        A list of encryption algorithms that the CMK supports. You cannot use the CMK with other encryption algorithms within AWS KMS.

        This field appears only when the KeyUsage of the CMK is ENCRYPT_DECRYPT.

        • (string) --

      • SigningAlgorithms (list) --

        A list of signing algorithms that the CMK supports. You cannot use the CMK with other signing algorithms within AWS KMS.

        This field appears only when the KeyUsage of the CMK is SIGN_VERIFY.

        • (string) --

Decrypt (updated) Link ¶
Changes (request, response)
Request
{'EncryptionAlgorithm': 'SYMMETRIC_DEFAULT | RSAES_OAEP_SHA_1 | '
                        'RSAES_OAEP_SHA_256',
 'KeyId': 'string'}
Response
{'EncryptionAlgorithm': 'SYMMETRIC_DEFAULT | RSAES_OAEP_SHA_1 | '
                        'RSAES_OAEP_SHA_256'}

Decrypts ciphertext that was encrypted by a AWS KMS customer master key (CMK) using any of the following operations:

  • Encrypt

  • GenerateDataKey

  • GenerateDataKeyPair

  • GenerateDataKeyWithoutPlaintext

  • GenerateDataKeyPairWithoutPlaintext

You can use this operation to decrypt ciphertext that was encrypted under a symmetric or asymmetric CMK. When the CMK is asymmetric, you must specify the CMK and the encryption algorithm that was used to encrypt the ciphertext. For information about symmetric and asymmetric CMKs, see Using Symmetric and Asymmetric CMKs in the AWS Key Management Service Developer Guide.

The Decrypt operation also decrypts ciphertext that was encrypted outside of AWS KMS by the public key in an AWS KMS asymmetric CMK. However, it cannot decrypt ciphertext produced by other libraries, such as the AWS Encryption SDK or Amazon S3 client-side encryption. These libraries return a ciphertext format that is incompatible with AWS KMS.

If the ciphertext was encrypted under a symmetric CMK, you do not need to specify the CMK or the encryption algorithm. AWS KMS can get this information from metadata that it adds to the symmetric ciphertext blob. However, if you prefer, you can specify the KeyId to ensure that a particular CMK is used to decrypt the ciphertext. If you specify a different CMK than the one used to encrypt the ciphertext, the Decrypt operation fails.

Whenever possible, use key policies to give users permission to call the Decrypt operation on a particular CMK, instead of using IAM policies. Otherwise, you might create an IAM user policy that gives the user Decrypt permission on all CMKs. This user could decrypt ciphertext that was encrypted by CMKs in other accounts if the key policy for the cross-account CMK permits it. If you must use an IAM policy for Decrypt permissions, limit the user to particular CMKs or particular trusted accounts.

The CMK that you use for this operation must be in a compatible key state. For details, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

See also: AWS API Documentation

Request Syntax

client.decrypt(
    CiphertextBlob=b'bytes',
    EncryptionContext={
        'string': 'string'
    },
    GrantTokens=[
        'string',
    ],
    KeyId='string',
    EncryptionAlgorithm='SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256'
)
type CiphertextBlob:

bytes

param CiphertextBlob:

[REQUIRED]

Ciphertext to be decrypted. The blob includes metadata.

type EncryptionContext:

dict

param EncryptionContext:

Specifies the encryption context to use when decrypting the data. An encryption context is valid only for cryptographic operations with a symmetric CMK. The standard asymmetric encryption algorithms that AWS KMS uses do not support an encryption context.

An encryption context is a collection of non-secret key-value pairs that represents additional authenticated data. When you use an encryption context to encrypt data, you must specify the same (an exact case-sensitive match) encryption context to decrypt the data. An encryption context is optional when encrypting with a symmetric CMK, but it is highly recommended.

For more information, see Encryption Context in the AWS Key Management Service Developer Guide.

  • (string) --

    • (string) --

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

  • (string) --

type KeyId:

string

param KeyId:

Specifies the customer master key (CMK) that AWS KMS will use to decrypt the ciphertext. Enter a key ID of the CMK that was used to encrypt the ciphertext.

If you specify a KeyId value, the Decrypt operation succeeds only if the specified CMK was used to encrypt the ciphertext.

This parameter is required only when the ciphertext was encrypted under an asymmetric CMK. Otherwise, AWS KMS uses the metadata that it adds to the ciphertext blob to determine which CMK was used to encrypt the ciphertext. However, you can use this parameter to ensure that a particular CMK (of any kind) is used to decrypt the ciphertext.

To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/".

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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

type EncryptionAlgorithm:

string

param EncryptionAlgorithm:

Specifies the encryption algorithm that will be used to decrypt the ciphertext. Specify the same algorithm that was used to encrypt the data. If you specify a different algorithm, the Decrypt operation fails.

This parameter is required only when the ciphertext was encrypted under an asymmetric CMK. The default value, SYMMETRIC_DEFAULT, represents the only supported algorithm that is valid for symmetric CMKs.

rtype:

dict

returns:

Response Syntax

{
    'KeyId': 'string',
    'Plaintext': b'bytes',
    'EncryptionAlgorithm': 'SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256'
}

Response Structure

  • (dict) --

    • KeyId (string) --

      The ARN of the customer master key that was used to perform the decryption.

    • Plaintext (bytes) --

      Decrypted plaintext data. When you use the HTTP API or the AWS CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded.

    • EncryptionAlgorithm (string) --

      The encryption algorithm that was used to decrypt the ciphertext.

DescribeKey (updated) Link ¶
Changes (response)
{'KeyMetadata': {'CustomerMasterKeySpec': 'RSA_2048 | RSA_3072 | RSA_4096 | '
                                          'ECC_NIST_P256 | ECC_NIST_P384 | '
                                          'ECC_NIST_P521 | ECC_SECG_P256K1 | '
                                          'SYMMETRIC_DEFAULT',
                 'EncryptionAlgorithms': ['SYMMETRIC_DEFAULT | '
                                          'RSAES_OAEP_SHA_1 | '
                                          'RSAES_OAEP_SHA_256'],
                 'KeyUsage': {'SIGN_VERIFY'},
                 'SigningAlgorithms': ['RSASSA_PSS_SHA_256 | '
                                       'RSASSA_PSS_SHA_384 | '
                                       'RSASSA_PSS_SHA_512 | '
                                       'RSASSA_PKCS1_V1_5_SHA_256 | '
                                       'RSASSA_PKCS1_V1_5_SHA_384 | '
                                       'RSASSA_PKCS1_V1_5_SHA_512 | '
                                       'ECDSA_SHA_256 | ECDSA_SHA_384 | '
                                       'ECDSA_SHA_512']}}

Provides detailed information about a customer master key (CMK). You can run DescribeKey on a customer managed CMK or an AWS managed CMK.

This detailed information includes the key ARN, creation date (and deletion date, if applicable), the key state, and the origin and expiration date (if any) of the key material. For CMKs in custom key stores, it includes information about the custom key store, such as the key store ID and the AWS CloudHSM cluster ID. It includes fields, like KeySpec, that help you distinguish symmetric from asymmetric CMKs. It also provides information that is particularly important to asymmetric CMKs, such as the key usage (encryption or signing) and the encryption algorithms or signing algorithms that the CMK supports.

DescribeKey does not return the following information:

  • Aliases associated with the CMK. To get this information, use ListAliases.

  • Whether automatic key rotation is enabled on the CMK. To get this information, use GetKeyRotationStatus. Also, some key states prevent a CMK from being automatically rotated. For details, see How Automatic Key Rotation Works in AWS Key Management Service Developer Guide.

  • Tags on the CMK. To get this information, use ListResourceTags.

  • Key policies and grants on the CMK. To get this information, use GetKeyPolicy and ListGrants.

If you call the DescribeKey operation on a predefined AWS alias, that is, an AWS alias with no key ID, AWS KMS creates an AWS managed CMK. Then, it associates the alias with the new CMK, and returns the KeyId and Arn of the new CMK in the response.

To perform this operation on a CMK in a different AWS account, specify the key ARN or alias ARN in the value of the KeyId parameter.

See also: AWS API Documentation

Request Syntax

client.describe_key(
    KeyId='string',
    GrantTokens=[
        'string',
    ]
)
type KeyId:

string

param KeyId:

[REQUIRED]

Describes the specified customer master key (CMK).

If you specify a predefined AWS alias (an AWS alias with no key ID), KMS associates the alias with an AWS managed CMK and returns its KeyId and Arn in the response.

To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/". To specify a CMK in a different AWS 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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

  • (string) --

rtype:

dict

returns:

Response Syntax

{
    'KeyMetadata': {
        'AWSAccountId': 'string',
        'KeyId': 'string',
        'Arn': 'string',
        'CreationDate': datetime(2015, 1, 1),
        'Enabled': True|False,
        'Description': 'string',
        'KeyUsage': 'SIGN_VERIFY'|'ENCRYPT_DECRYPT',
        'KeyState': 'Enabled'|'Disabled'|'PendingDeletion'|'PendingImport'|'Unavailable',
        'DeletionDate': datetime(2015, 1, 1),
        'ValidTo': datetime(2015, 1, 1),
        'Origin': 'AWS_KMS'|'EXTERNAL'|'AWS_CLOUDHSM',
        'CustomKeyStoreId': 'string',
        'CloudHsmClusterId': 'string',
        'ExpirationModel': 'KEY_MATERIAL_EXPIRES'|'KEY_MATERIAL_DOES_NOT_EXPIRE',
        'KeyManager': 'AWS'|'CUSTOMER',
        'CustomerMasterKeySpec': 'RSA_2048'|'RSA_3072'|'RSA_4096'|'ECC_NIST_P256'|'ECC_NIST_P384'|'ECC_NIST_P521'|'ECC_SECG_P256K1'|'SYMMETRIC_DEFAULT',
        'EncryptionAlgorithms': [
            'SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256',
        ],
        'SigningAlgorithms': [
            'RSASSA_PSS_SHA_256'|'RSASSA_PSS_SHA_384'|'RSASSA_PSS_SHA_512'|'RSASSA_PKCS1_V1_5_SHA_256'|'RSASSA_PKCS1_V1_5_SHA_384'|'RSASSA_PKCS1_V1_5_SHA_512'|'ECDSA_SHA_256'|'ECDSA_SHA_384'|'ECDSA_SHA_512',
        ]
    }
}

Response Structure

  • (dict) --

    • KeyMetadata (dict) --

      Metadata associated with the key.

      • AWSAccountId (string) --

        The twelve-digit account ID of the AWS account that owns the CMK.

      • KeyId (string) --

        The globally unique identifier for the CMK.

      • Arn (string) --

        The Amazon Resource Name (ARN) of the CMK. For examples, see AWS Key Management Service (AWS KMS) in the Example ARNs section of the AWS General Reference.

      • CreationDate (datetime) --

        The date and time when the CMK was created.

      • Enabled (boolean) --

        Specifies whether the CMK is enabled. When KeyState is Enabled this value is true, otherwise it is false.

      • Description (string) --

        The description of the CMK.

      • KeyUsage (string) --

        The cryptographic operations for which you can use the CMK.

      • KeyState (string) --

        The state of the CMK.

        For more information about how key state affects the use of a CMK, see How Key State Affects the Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

      • DeletionDate (datetime) --

        The date and time after which AWS KMS deletes the CMK. This value is present only when KeyState is PendingDeletion.

      • ValidTo (datetime) --

        The time at which the imported key material expires. When the key material expires, AWS KMS deletes the key material and the CMK becomes unusable. This value is present only for CMKs whose Origin is EXTERNAL and whose ExpirationModel is KEY_MATERIAL_EXPIRES, otherwise this value is omitted.

      • Origin (string) --

        The source of the CMK's key material. When this value is AWS_KMS, AWS KMS created the key material. When this value is EXTERNAL, the key material was imported from your existing key management infrastructure or the CMK lacks key material. When this value is AWS_CLOUDHSM, the key material was created in the AWS CloudHSM cluster associated with a custom key store.

      • CustomKeyStoreId (string) --

        A unique identifier for the custom key store that contains the CMK. This value is present only when the CMK is created in a custom key store.

      • CloudHsmClusterId (string) --

        The cluster ID of the AWS CloudHSM cluster that contains the key material for the CMK. When you create a CMK in a custom key store, AWS KMS creates the key material for the CMK in the associated AWS CloudHSM cluster. This value is present only when the CMK is created in a custom key store.

      • ExpirationModel (string) --

        Specifies whether the CMK's key material expires. This value is present only when Origin is EXTERNAL, otherwise this value is omitted.

      • KeyManager (string) --

        The manager of the CMK. CMKs in your AWS account are either customer managed or AWS managed. For more information about the difference, see Customer Master Keys in the AWS Key Management Service Developer Guide.

      • CustomerMasterKeySpec (string) --

        Describes the type of key material in the CMK.

      • EncryptionAlgorithms (list) --

        A list of encryption algorithms that the CMK supports. You cannot use the CMK with other encryption algorithms within AWS KMS.

        This field appears only when the KeyUsage of the CMK is ENCRYPT_DECRYPT.

        • (string) --

      • SigningAlgorithms (list) --

        A list of signing algorithms that the CMK supports. You cannot use the CMK with other signing algorithms within AWS KMS.

        This field appears only when the KeyUsage of the CMK is SIGN_VERIFY.

        • (string) --

Encrypt (updated) Link ¶
Changes (both)
{'EncryptionAlgorithm': 'SYMMETRIC_DEFAULT | RSAES_OAEP_SHA_1 | '
                        'RSAES_OAEP_SHA_256'}

Encrypts plaintext into ciphertext by using a customer master key (CMK). The Encrypt operation has two primary use cases:

  • You can encrypt small amounts of arbitrary data, such as a personal identifier or database password, or other sensitive information.

  • You can use the Encrypt operation to move encrypted data from one AWS region to another. In the first region, generate a data key and use the plaintext key to encrypt the data. Then, in the new region, call the Encrypt method on same plaintext data key. Now, you can safely move the encrypted data and encrypted data key to the new region, and decrypt in the new region when necessary.

You don't need to use the Encrypt operation to encrypt a data key. The GenerateDataKey and GenerateDataKeyPair operations return a plaintext data key and an encrypted copy of that data key.

When you encrypt data, you must specify a symmetric or asymmetric CMK to use in the encryption operation. The CMK must have a KeyUsage value of ENCRYPT_DECRYPT. To find the KeyUsage of a CMK, use the DescribeKey operation.

If you use a symmetric CMK, you can use an encryption context to add additional security to your encryption operation. If you specify an EncryptionContext when encrypting data, you must specify the same encryption context (a case-sensitive exact match) when decrypting the data. Otherwise, the request to decrypt fails with an InvalidCiphertextException. For more information, see Encryption Context in the AWS Key Management Service Developer Guide.

If you specify an asymmetric CMK, you must also specify the encryption algorithm. The algorithm must be compatible with the CMK type.

The maximum size of the data that you can encrypt varies with the type of CMK and the encryption algorithm that you choose.

  • Symmetric CMKs

    • SYMMETRIC_DEFAULT: 4096 bytes

  • RSA_2048

    • RSAES_OAEP_SHA_1: 214 bytes

    • RSAES_OAEP_SHA_256: 190 bytes

  • RSA_3072

    • RSAES_OAEP_SHA_1: 342 bytes

    • RSAES_OAEP_SHA_256: 318 bytes

  • RSA_4096

    • RSAES_OAEP_SHA_1: 470 bytes

    • RSAES_OAEP_SHA_256: 446 bytes

The CMK that you use for this operation must be in a compatible key state. For details, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

To perform this operation on a CMK in a different AWS account, specify the key ARN or alias ARN in the value of the KeyId parameter.

See also: AWS API Documentation

Request Syntax

client.encrypt(
    KeyId='string',
    Plaintext=b'bytes',
    EncryptionContext={
        'string': 'string'
    },
    GrantTokens=[
        'string',
    ],
    EncryptionAlgorithm='SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256'
)
type KeyId:

string

param KeyId:

[REQUIRED]

A unique identifier for the customer master key (CMK).

To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/". To specify a CMK in a different AWS 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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

type Plaintext:

bytes

param Plaintext:

[REQUIRED]

Data to be encrypted.

type EncryptionContext:

dict

param EncryptionContext:

Specifies the encryption context that will be used to encrypt the data. An encryption context is valid only for cryptographic operations with a symmetric CMK. The standard asymmetric encryption algorithms that AWS KMS uses do not support an encryption context.

An encryption context is a collection of non-secret key-value pairs that represents additional authenticated data. When you use an encryption context to encrypt data, you must specify the same (an exact case-sensitive match) encryption context to decrypt the data. An encryption context is optional when encrypting with a symmetric CMK, but it is highly recommended.

For more information, see Encryption Context in the AWS Key Management Service Developer Guide.

  • (string) --

    • (string) --

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

  • (string) --

type EncryptionAlgorithm:

string

param EncryptionAlgorithm:

Specifies the encryption algorithm that AWS KMS will use to encrypt the plaintext message. The algorithm must be compatible with the CMK that you specify.

This parameter is required only for asymmetric CMKs. The default value, SYMMETRIC_DEFAULT, is the algorithm used for symmetric CMKs. If you are using an asymmetric CMK, we recommend RSAES_OAEP_SHA_256.

rtype:

dict

returns:

Response Syntax

{
    'CiphertextBlob': b'bytes',
    'KeyId': 'string',
    'EncryptionAlgorithm': 'SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256'
}

Response Structure

  • (dict) --

    • CiphertextBlob (bytes) --

      The encrypted plaintext. When you use the HTTP API or the AWS CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded.

    • KeyId (string) --

      The ID of the key used during encryption.

    • EncryptionAlgorithm (string) --

      The encryption algorithm that was used to encrypt the plaintext.

ListGrants (updated) Link ¶
Changes (response)
{'Grants': {'Operations': {'GenerateDataKeyPair',
                           'GenerateDataKeyPairWithoutPlaintext',
                           'GetPublicKey',
                           'Sign',
                           'Verify'}}}

Gets a list of all grants for the specified customer master key (CMK).

To perform this operation on a CMK in a different AWS account, specify the key ARN in the value of the KeyId parameter.

See also: AWS API Documentation

Request Syntax

client.list_grants(
    Limit=123,
    Marker='string',
    KeyId='string'
)
type Limit:

integer

param Limit:

Use this parameter to specify the maximum number of items to return. When this value is present, AWS KMS does not return more than the specified number of items, but it might return fewer.

This value is optional. If you include a value, it must be between 1 and 100, inclusive. If you do not include a value, it defaults to 50.

type Marker:

string

param Marker:

Use this parameter in a subsequent request after you receive a response with truncated results. Set it to the value of NextMarker from the truncated response you just received.

type KeyId:

string

param KeyId:

[REQUIRED]

A unique identifier for the customer master key (CMK).

Specify the key ID or the Amazon Resource Name (ARN) of the CMK. To specify a CMK in a different AWS account, you must use the key 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

To get the key ID and key ARN for a CMK, use ListKeys or DescribeKey.

rtype:

dict

returns:

Response Syntax

{
    'Grants': [
        {
            'KeyId': 'string',
            'GrantId': 'string',
            'Name': 'string',
            'CreationDate': datetime(2015, 1, 1),
            'GranteePrincipal': 'string',
            'RetiringPrincipal': 'string',
            'IssuingAccount': 'string',
            'Operations': [
                'Decrypt'|'Encrypt'|'GenerateDataKey'|'GenerateDataKeyWithoutPlaintext'|'ReEncryptFrom'|'ReEncryptTo'|'Sign'|'Verify'|'GetPublicKey'|'CreateGrant'|'RetireGrant'|'DescribeKey'|'GenerateDataKeyPair'|'GenerateDataKeyPairWithoutPlaintext',
            ],
            'Constraints': {
                'EncryptionContextSubset': {
                    'string': 'string'
                },
                'EncryptionContextEquals': {
                    'string': 'string'
                }
            }
        },
    ],
    'NextMarker': 'string',
    'Truncated': True|False
}

Response Structure

  • (dict) --

    • Grants (list) --

      A list of grants.

      • (dict) --

        Contains information about an entry in a list of grants.

        • KeyId (string) --

          The unique identifier for the customer master key (CMK) to which the grant applies.

        • GrantId (string) --

          The unique identifier for the grant.

        • Name (string) --

          The friendly name that identifies the grant. If a name was provided in the CreateGrant request, that name is returned. Otherwise this value is null.

        • CreationDate (datetime) --

          The date and time when the grant was created.

        • GranteePrincipal (string) --

          The principal that receives the grant's permissions.

        • RetiringPrincipal (string) --

          The principal that can retire the grant.

        • IssuingAccount (string) --

          The AWS account under which the grant was issued.

        • Operations (list) --

          The list of operations permitted by the grant.

          • (string) --

        • Constraints (dict) --

          A list of key-value pairs that must be present in the encryption context of certain subsequent operations that the grant allows.

          • EncryptionContextSubset (dict) --

            A list of key-value pairs that must be included in the encryption context of the cryptographic operation request. The grant allows the cryptographic operation only when the encryption context in the request includes the key-value pairs specified in this constraint, although it can include additional key-value pairs.

            • (string) --

              • (string) --

          • EncryptionContextEquals (dict) --

            A list of key-value pairs that must match the encryption context in the cryptographic operation request. The grant allows the operation only when the encryption context in the request is the same as the encryption context specified in this constraint.

            • (string) --

              • (string) --

    • NextMarker (string) --

      When Truncated is true, this element is present and contains the value to use for the Marker parameter in a subsequent request.

    • Truncated (boolean) --

      A flag that indicates whether there are more items in the list. When this value is true, the list in this response is truncated. To get more items, pass the value of the NextMarker element in thisresponse to the Marker parameter in a subsequent request.

ListRetirableGrants (updated) Link ¶
Changes (response)
{'Grants': {'Operations': {'GenerateDataKeyPair',
                           'GenerateDataKeyPairWithoutPlaintext',
                           'GetPublicKey',
                           'Sign',
                           'Verify'}}}

Returns a list of all grants for which the grant's RetiringPrincipal matches the one specified.

A typical use is to list all grants that you are able to retire. To retire a grant, use RetireGrant.

See also: AWS API Documentation

Request Syntax

client.list_retirable_grants(
    Limit=123,
    Marker='string',
    RetiringPrincipal='string'
)
type Limit:

integer

param Limit:

Use this parameter to specify the maximum number of items to return. When this value is present, AWS KMS does not return more than the specified number of items, but it might return fewer.

This value is optional. If you include a value, it must be between 1 and 100, inclusive. If you do not include a value, it defaults to 50.

type Marker:

string

param Marker:

Use this parameter in a subsequent request after you receive a response with truncated results. Set it to the value of NextMarker from the truncated response you just received.

type RetiringPrincipal:

string

param RetiringPrincipal:

[REQUIRED]

The retiring principal for which to list grants.

To specify the retiring principal, use the Amazon Resource Name (ARN) of an AWS principal. Valid AWS principals include AWS accounts (root), IAM users, federated users, and assumed role users. For examples of the ARN syntax for specifying a principal, see AWS Identity and Access Management (IAM) in the Example ARNs section of the Amazon Web Services General Reference.

rtype:

dict

returns:

Response Syntax

{
    'Grants': [
        {
            'KeyId': 'string',
            'GrantId': 'string',
            'Name': 'string',
            'CreationDate': datetime(2015, 1, 1),
            'GranteePrincipal': 'string',
            'RetiringPrincipal': 'string',
            'IssuingAccount': 'string',
            'Operations': [
                'Decrypt'|'Encrypt'|'GenerateDataKey'|'GenerateDataKeyWithoutPlaintext'|'ReEncryptFrom'|'ReEncryptTo'|'Sign'|'Verify'|'GetPublicKey'|'CreateGrant'|'RetireGrant'|'DescribeKey'|'GenerateDataKeyPair'|'GenerateDataKeyPairWithoutPlaintext',
            ],
            'Constraints': {
                'EncryptionContextSubset': {
                    'string': 'string'
                },
                'EncryptionContextEquals': {
                    'string': 'string'
                }
            }
        },
    ],
    'NextMarker': 'string',
    'Truncated': True|False
}

Response Structure

  • (dict) --

    • Grants (list) --

      A list of grants.

      • (dict) --

        Contains information about an entry in a list of grants.

        • KeyId (string) --

          The unique identifier for the customer master key (CMK) to which the grant applies.

        • GrantId (string) --

          The unique identifier for the grant.

        • Name (string) --

          The friendly name that identifies the grant. If a name was provided in the CreateGrant request, that name is returned. Otherwise this value is null.

        • CreationDate (datetime) --

          The date and time when the grant was created.

        • GranteePrincipal (string) --

          The principal that receives the grant's permissions.

        • RetiringPrincipal (string) --

          The principal that can retire the grant.

        • IssuingAccount (string) --

          The AWS account under which the grant was issued.

        • Operations (list) --

          The list of operations permitted by the grant.

          • (string) --

        • Constraints (dict) --

          A list of key-value pairs that must be present in the encryption context of certain subsequent operations that the grant allows.

          • EncryptionContextSubset (dict) --

            A list of key-value pairs that must be included in the encryption context of the cryptographic operation request. The grant allows the cryptographic operation only when the encryption context in the request includes the key-value pairs specified in this constraint, although it can include additional key-value pairs.

            • (string) --

              • (string) --

          • EncryptionContextEquals (dict) --

            A list of key-value pairs that must match the encryption context in the cryptographic operation request. The grant allows the operation only when the encryption context in the request is the same as the encryption context specified in this constraint.

            • (string) --

              • (string) --

    • NextMarker (string) --

      When Truncated is true, this element is present and contains the value to use for the Marker parameter in a subsequent request.

    • Truncated (boolean) --

      A flag that indicates whether there are more items in the list. When this value is true, the list in this response is truncated. To get more items, pass the value of the NextMarker element in thisresponse to the Marker parameter in a subsequent request.

ReEncrypt (updated) Link ¶
Changes (request, response)
Request
{'DestinationEncryptionAlgorithm': 'SYMMETRIC_DEFAULT | RSAES_OAEP_SHA_1 | '
                                   'RSAES_OAEP_SHA_256',
 'SourceEncryptionAlgorithm': 'SYMMETRIC_DEFAULT | RSAES_OAEP_SHA_1 | '
                              'RSAES_OAEP_SHA_256',
 'SourceKeyId': 'string'}
Response
{'DestinationEncryptionAlgorithm': 'SYMMETRIC_DEFAULT | RSAES_OAEP_SHA_1 | '
                                   'RSAES_OAEP_SHA_256',
 'SourceEncryptionAlgorithm': 'SYMMETRIC_DEFAULT | RSAES_OAEP_SHA_1 | '
                              'RSAES_OAEP_SHA_256'}

Decrypts ciphertext and then reencrypts it entirely within AWS KMS. You can use this operation to change the customer master key (CMK) under which data is encrypted, such as when you manually rotate a CMK or change the CMK that protects a ciphertext. You can also use it to reencrypt ciphertext under the same CMK, such as to change the encryption context of a ciphertext.

The ReEncrypt operation can decrypt ciphertext that was encrypted by using an AWS KMS CMK in an AWS KMS operation, such as Encrypt or GenerateDataKey. It can also decrypt ciphertext that was encrypted by using the public key of an asymmetric CMK outside of AWS KMS. However, it cannot decrypt ciphertext produced by other libraries, such as the AWS Encryption SDK or Amazon S3 client-side encryption. These libraries return a ciphertext format that is incompatible with AWS KMS.

When you use the ReEncrypt operation, you need to provide information for the decrypt operation and the subsequent encrypt operation.

  • If your ciphertext was encrypted under an asymmetric CMK, you must identify the source CMK, that is, the CMK that encrypted the ciphertext. You must also supply the encryption algorithm that was used. This information is required to decrypt the data.

  • It is optional, but you can specify a source CMK even when the ciphertext was encrypted under a symmetric CMK. This ensures that the ciphertext is decrypted only by using a particular CMK. If the CMK that you specify cannot decrypt the ciphertext, the ReEncrypt operation fails.

  • To reencrypt the data, you must specify the destination CMK, that is, the CMK that re-encrypts the data after it is decrypted. You can select a symmetric or asymmetric CMK. If the destination CMK is an asymmetric CMK, you must also provide the encryption algorithm. The algorithm that you choose must be compatible with the CMK.

Unlike other AWS KMS API operations, ReEncrypt callers must have two permissions:

  • kms:EncryptFrom permission on the source CMK

  • kms:EncryptTo permission on the destination CMK

To permit reencryption from

or to a CMK, include the "kms:ReEncrypt*" permission in your key policy. This permission is automatically included in the key policy when you use the console to create a CMK. But you must include it manually when you create a CMK programmatically or when you use the PutKeyPolicy operation set a key policy.

The CMK that you use for this operation must be in a compatible key state. For details, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

See also: AWS API Documentation

Request Syntax

client.re_encrypt(
    CiphertextBlob=b'bytes',
    SourceEncryptionContext={
        'string': 'string'
    },
    SourceKeyId='string',
    DestinationKeyId='string',
    DestinationEncryptionContext={
        'string': 'string'
    },
    SourceEncryptionAlgorithm='SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256',
    DestinationEncryptionAlgorithm='SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256',
    GrantTokens=[
        'string',
    ]
)
type CiphertextBlob:

bytes

param CiphertextBlob:

[REQUIRED]

Ciphertext of the data to reencrypt.

type SourceEncryptionContext:

dict

param SourceEncryptionContext:

Specifies the encryption context to use to decrypt the ciphertext. Enter the same encryption context that was used to encrypt the ciphertext.

An encryption context is a collection of non-secret key-value pairs that represents additional authenticated data. When you use an encryption context to encrypt data, you must specify the same (an exact case-sensitive match) encryption context to decrypt the data. An encryption context is optional when encrypting with a symmetric CMK, but it is highly recommended.

For more information, see Encryption Context in the AWS Key Management Service Developer Guide.

  • (string) --

    • (string) --

type SourceKeyId:

string

param SourceKeyId:

A unique identifier for the CMK that is used to decrypt the ciphertext before it reencrypts it using the destination CMK.

This parameter is required only when the ciphertext was encrypted under an asymmetric CMK. Otherwise, AWS KMS uses the metadata that it adds to the ciphertext blob to determine which CMK was used to encrypt the ciphertext. However, you can use this parameter to ensure that a particular CMK (of any kind) is used to decrypt the ciphertext before it is reencrypted.

If you specify a KeyId value, the decrypt part of the ReEncrypt operation succeeds only if the specified CMK was used to encrypt the ciphertext.

To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/".

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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

type DestinationKeyId:

string

param DestinationKeyId:

[REQUIRED]

A unique identifier for the CMK that is used to reencrypt the data. Specify a symmetric or asymmetric CMK with a KeyUsage value of ENCRYPT_DECRYPT. To find the KeyUsage value of a CMK, use the DescribeKey operation.

To specify a CMK, use its key ID, Amazon Resource Name (ARN), alias name, or alias ARN. When using an alias name, prefix it with "alias/". To specify a CMK in a different AWS 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 CMK, use ListKeys or DescribeKey. To get the alias name and alias ARN, use ListAliases.

type DestinationEncryptionContext:

dict

param DestinationEncryptionContext:

Specifies that encryption context to use when the reencrypting the data.

A destination encryption context is valid only when the destination CMK is a symmetric CMK. The standard ciphertext format for asymmetric CMKs does not include fields for metadata.

An encryption context is a collection of non-secret key-value pairs that represents additional authenticated data. When you use an encryption context to encrypt data, you must specify the same (an exact case-sensitive match) encryption context to decrypt the data. An encryption context is optional when encrypting with a symmetric CMK, but it is highly recommended.

For more information, see Encryption Context in the AWS Key Management Service Developer Guide.

  • (string) --

    • (string) --

type SourceEncryptionAlgorithm:

string

param SourceEncryptionAlgorithm:

Specifies the encryption algorithm that AWS KMS will use to decrypt the ciphertext before it is reencrypted. The default value, SYMMETRIC_DEFAULT, represents the algorithm used for symmetric CMKs.

Specify the same algorithm that was used to encrypt the ciphertext. If you specify a different algorithm, the decrypt attempt fails.

This parameter is required only when the ciphertext was encrypted under an asymmetric CMK.

type DestinationEncryptionAlgorithm:

string

param DestinationEncryptionAlgorithm:

Specifies the encryption algorithm that AWS KMS will use to reecrypt the data after it has decrypted it. The default value, SYMMETRIC_DEFAULT, represents the encryption algorithm used for symmetric CMKs.

This parameter is required only when the destination CMK is an asymmetric CMK.

type GrantTokens:

list

param GrantTokens:

A list of grant tokens.

For more information, see Grant Tokens in the AWS Key Management Service Developer Guide.

  • (string) --

rtype:

dict

returns:

Response Syntax

{
    'CiphertextBlob': b'bytes',
    'SourceKeyId': 'string',
    'KeyId': 'string',
    'SourceEncryptionAlgorithm': 'SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256',
    'DestinationEncryptionAlgorithm': 'SYMMETRIC_DEFAULT'|'RSAES_OAEP_SHA_1'|'RSAES_OAEP_SHA_256'
}

Response Structure

  • (dict) --

    • CiphertextBlob (bytes) --

      The reencrypted data. When you use the HTTP API or the AWS CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded.

    • SourceKeyId (string) --

      Unique identifier of the CMK used to originally encrypt the data.

    • KeyId (string) --

      Unique identifier of the CMK used to reencrypt the data.

    • SourceEncryptionAlgorithm (string) --

      The encryption algorithm that was used to decrypt the ciphertext before it was reencrypted.

    • DestinationEncryptionAlgorithm (string) --

      The encryption algorithm that was used to reencrypt the data.