/AWS1/CL_KMS=>GETPUBLICKEY()
¶
About GetPublicKey¶
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:
-
KeySpec: The type of key material in the public key, such as
RSA_4096
orECC_NIST_P521
. -
KeyUsage: Whether the key is used for encryption, signing, or deriving a shared secret.
-
EncryptionAlgorithms or SigningAlgorithms: A list of the encryption algorithms or the signing algorithms for the key.
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.
Method Signature¶
IMPORTING¶
Required arguments:¶
iv_keyid
TYPE /AWS1/KMSKEYIDTYPE
/AWS1/KMSKEYIDTYPE
¶
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.
Optional arguments:¶
it_granttokens
TYPE /AWS1/CL_KMSGRANTTOKENLIST_W=>TT_GRANTTOKENLIST
TT_GRANTTOKENLIST
¶
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.
RETURNING¶
oo_output
TYPE REF TO /aws1/cl_kmsgetpublickeyrsp
/AWS1/CL_KMSGETPUBLICKEYRSP
¶
Domain /AWS1/RT_ACCOUNT_ID Primitive Type NUMC
Examples¶
Syntax Example¶
This is an example of the syntax for calling the method. It includes every possible argument and initializes every possible value. The data provided is not necessarily semantically accurate (for example the value "string" may be provided for something that is intended to be an instance ID, or in some cases two arguments may be mutually exclusive). The syntax shows the ABAP syntax for creating the various data structures.
DATA(lo_result) = lo_client->/aws1/if_kms~getpublickey(
it_granttokens = VALUE /aws1/cl_kmsgranttokenlist_w=>tt_granttokenlist(
( new /aws1/cl_kmsgranttokenlist_w( |string| ) )
)
iv_keyid = |string|
).
This is an example of reading all possible response values
lo_result = lo_result.
IF lo_result IS NOT INITIAL.
lv_keyidtype = lo_result->get_keyid( ).
lv_publickeytype = lo_result->get_publickey( ).
lv_customermasterkeyspec = lo_result->get_customermasterkeyspec( ).
lv_keyspec = lo_result->get_keyspec( ).
lv_keyusagetype = lo_result->get_keyusage( ).
LOOP AT lo_result->get_encryptionalgorithms( ) into lo_row.
lo_row_1 = lo_row.
IF lo_row_1 IS NOT INITIAL.
lv_encryptionalgorithmspec = lo_row_1->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_result->get_signingalgorithms( ) into lo_row_2.
lo_row_3 = lo_row_2.
IF lo_row_3 IS NOT INITIAL.
lv_signingalgorithmspec = lo_row_3->get_value( ).
ENDIF.
ENDLOOP.
LOOP AT lo_result->get_keyagreementalgorithms( ) into lo_row_4.
lo_row_5 = lo_row_4.
IF lo_row_5 IS NOT INITIAL.
lv_keyagreementalgorithmsp = lo_row_5->get_value( ).
ENDIF.
ENDLOOP.
ENDIF.
To download the public key of an asymmetric KMS key¶
This example gets the public key of an asymmetric RSA KMS key used for encryption and decryption. The operation returns the key spec, key usage, and encryption or signing algorithms to help you use the public key correctly outside of AWS KMS.
DATA(lo_result) = lo_client->/aws1/if_kms~getpublickey( iv_keyid = |arn:aws:kms:us-west-2:111122223333:key/0987dcba-09fe-87dc-65ba-ab0987654321| ) .