Skip to content

KMS  >  Operations  >  get_public_key

get_public_key

Operation

get_public_key async

get_public_key(request: GetPublicKeyInput | GetPublicKeyInputDict, /, *, plugins: list[Plugin] | None = None) -> GetPublicKeyOutput
get_public_key(*, plugins: list[Plugin] | None = None, **kwargs: Unpack[GetPublicKeyInputDict]) -> GetPublicKeyOutput

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

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

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

Although 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 KMS. You can also avoid errors, such as using the wrong signing algorithm in a verification operation.

To verify a signature outside of KMS with an SM2 public key (China Regions only), you must specify the distinguishing ID. By default, KMS uses 1234567812345678 as the distinguishing ID. For more information, see Offline verification with SM2 key pairs.

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:GetPublicKey (key policy)

Related operations: CreateKey

Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.

Parameters:

Name Type Description Default
plugins list[Plugin] | None

A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations.

None

Returns:

Type Description
GetPublicKeyOutput

An instance of GetPublicKeyOutput.

Input

Pass the input fields as keyword arguments, or pass a model or dictionary as the first positional argument. Pass plugins separately as a keyword argument.

Model

GetPublicKeyInput dataclass

Bases: _SerdeShape

Dataclass for GetPublicKeyInput structure.

Attributes
grant_tokens class-attribute instance-attribute
grant_tokens: list[str] | 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.

key_id class-attribute instance-attribute
key_id: str | None = ...

Identifies the asymmetric KMS key that includes the public key.

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.

Dictionaries

GetPublicKeyInputDict

Bases: TypedDict

Dictionary form of GetPublicKeyInput.

Attributes
grant_tokens instance-attribute
grant_tokens: Sequence[str] | 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.

key_id instance-attribute
key_id: Required[str]

Identifies the asymmetric KMS key that includes the public key.

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.

Output

GetPublicKeyOutput dataclass

Bases: _SerdeShape

Dataclass for GetPublicKeyOutput structure.

Attributes

customer_master_key_spec class-attribute instance-attribute
customer_master_key_spec: str | None = ...

Instead, use the KeySpec field in the GetPublicKey response.

The KeySpec and CustomerMasterKeySpec fields have the same value. We recommend that you use the KeySpec field in your code. However, to avoid breaking changes, KMS supports both fields.

encapsulation_algorithms class-attribute instance-attribute
encapsulation_algorithms: list[str] | None = ...

The key encapsulation algorithm used to establish a shared secret. This field is present only when the KMS key has a KeyUsage value of ENCAPSULATE_DECAPSULATE.

encryption_algorithms class-attribute instance-attribute
encryption_algorithms: list[str] | None = ...

The encryption algorithms that KMS supports for this key.

This information is critical. If a public key encrypts data outside of 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.

key_agreement_algorithms class-attribute instance-attribute
key_agreement_algorithms: list[str] | None = ...

The key agreement algorithm used to derive a shared secret. This field is present only when the KMS key has a KeyUsage value of KEY_AGREEMENT.

key_id class-attribute instance-attribute
key_id: str | None = ...

The Amazon Resource Name (key ARN) of the asymmetric KMS key from which the public key was downloaded.

key_spec class-attribute instance-attribute
key_spec: str | None = ...

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

key_usage class-attribute instance-attribute
key_usage: str | None = ...

The permitted use of the public key. Valid values for asymmetric key pairs are ENCRYPT_DECRYPT, SIGN_VERIFY, and KEY_AGREEMENT.

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

public_key class-attribute instance-attribute
public_key: bytes | None = ...

The exported public key.

The value is a DER-encoded X.509 public key, also known as SubjectPublicKeyInfo (SPKI), as defined in RFC 5280. When you use the HTTP API or the Amazon Web Services CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded.

response_metadata class-attribute instance-attribute
response_metadata: ResponseMetadata = ...

Metadata about the response that produced this output. Use this to recover the request identifiers a service's support team needs in order to investigate a call. Members of the metadata are individually optional.

signing_algorithms class-attribute instance-attribute
signing_algorithms: list[str] | None = ...

The signing algorithms that KMS supports for this key.

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