You can retrieve the public key portion of an asymmetric key version by using
the Google Cloud Console, the gcloud
command-line tool, and the Cloud Key Management Service API.
The public key is in the Privacy-enhanced Electronic Mail (PEM) format. For more information, see the RFC 7468 sections for General Considerations and Textual Encoding of Subject Public Key Info.
The user or service that will retrieve the public key requires
cloudkms.cryptoKeyVersions.viewPublicKey
permission on the key version. You
can learn about permissions in the Cloud KMS beta release at
Permissions and Roles.
To download the public key for an existing asymmetric key version:
Web UI
Go to the Cryptographic Keys page in the Cloud Console.
Click the name of the key ring that contains the asymmetric key for which you want to retrieve the public key.
Click on the name of the key for which you want to retrieve the public key.
On the row corresponding to the key version for which you want to retrieve the public key, click View More
.Click Get public key.
The public key is displayed in the prompt. You can copy the public key to your clipboard. To download the public key, click Download.
If you do not see the Get public key option, verify the key is an asymmetric
key and that you have the cloudkms.cryptoKeyVersions.viewPublicKey
permission.
The file name of a public key downloaded from the Cloud Console is of the form:
[key-ring]-[key-name]-[key-version].pub
Each portion of the file name is separated by a hyphen.
Command-line
To use Cloud KMS on the command line, first Install or upgrade to the latest version of Cloud SDK.
gcloud kms keys versions get-public-key key-version \ --key key \ --keyring key-ring-name \ --location location \ --output-file public-key.pub
Replace key-version with the key version. Replace key with the name of the key. Replace key-ring with the name of the key ring where the key is stored. Replace location with the Cloud KMS location for the key ring. Replace public-key.pub with the file path to save the public key.
For information on all flags and possible values, run the command with the
--help
flag.
C#
To run this code, first set up a C# development environment and install the Cloud KMS C# SDK.
Go
To run this code, first set up a Go development environment and install the Cloud KMS Go SDK.
Java
To run this code, first set up a Java development environment and install the Cloud KMS Java SDK.
Node.js
To run this code, first set up a Node.js development environment and install the Cloud KMS Node.js SDK.
PHP
To run this code, first learn about using PHP on Google Cloud and install the Cloud KMS PHP SDK.
Python
To run this code, first set up a Python development environment and install the Cloud KMS Python SDK.
Ruby
To run this code, first set up a Ruby development environment and install the Cloud KMS Ruby SDK.
API
These examples use curl as an HTTP client to demonstrate using the API. For more information about access control, see Accessing the Cloud KMS API.
Retrieve the public key by calling the CryptoKeyVersions.getPublicKey method.