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:
CustomerMasterKeySpec : The type of key material in the public key, such as RSA_4096
or ECC_NIST_P521
.
KeyUsage : Whether the key is used for encryption or signing.
EncryptionAlgorithms or SigningAlgorithms : A list of the encryption algorithms or the signing algorithms for the key.
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
See ‘aws help’ for descriptions of global parameters.
get-public-key
--key-id <value>
[--grant-tokens <value>]
[--cli-input-json | --cli-input-yaml]
[--generate-cli-skeleton <value>]
[--cli-auto-prompt <value>]
--key-id
(string)
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 .
--grant-tokens
(list)
A list of grant tokens.
For more information, see Grant Tokens in the AWS Key Management Service Developer Guide .
(string)
Syntax:
"string" "string" ...
--cli-input-json
| --cli-input-yaml
(string)
Reads arguments from the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton
. If other arguments are provided on the command line, those values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally. This may not be specified along with --cli-input-yaml
.
--generate-cli-skeleton
(string)
Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input
, prints a sample input JSON that can be used as an argument for --cli-input-json
. Similarly, if provided yaml-input
it will print a sample input YAML that can be used with --cli-input-yaml
. If provided with the value output
, it validates the command inputs and returns a sample output JSON for that command.
--cli-auto-prompt
(boolean)
Automatically prompt for CLI input parameters.
See ‘aws help’ for descriptions of global parameters.
KeyId -> (string)
The Amazon Resource Name (key ARN ) of the asymmetric CMK from which the public key was downloaded.
PublicKey -> (blob)
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 AWS CLI, the value is Base64-encoded. Otherwise, it is not Base64-encoded.
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
orSIGN_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 isENCRYPT_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 isSIGN_VERIFY
.(string)