This page shows how to create an asymmetric key. You can use an asymmetric key for encryption or for signing.
You can also create a symmetric key, a Cloud HSM key, or a Cloud External Key Manager key.
Overview
When you create a key, you add it to a key ring in a given Google Cloud location. You can create a new key ring or use an existing one. In this topic, you create a new key ring and add a new key to it.
Create a key ring
Follow these steps to create a key ring for your new key. If you want to use an existing key ring instead, you can create a key.
Web UI
Go to the Cryptographic Keys page in the Cloud Console.
Click Create key ring.
In the Key ring name field, enter the desired name for your key ring.
From the Key ring location dropdown, select a location like
"us-east1"
.Click Create.
Command-line
To use Cloud KMS on the command line, first Install or upgrade to the latest version of Cloud SDK.
gcloud kms keyrings create key-ring \ --location location
Replace key-ring with a name for the key ring. Replace location with the Cloud KMS location for the key ring and its keys.
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.
curl "https://cloudkms.googleapis.com/v1/projects/project-id/locations/location-id/keyRings" \ --request "POST" \ --header "authorization: Bearer token" \ --header "content-type: application/json" \ --header "x-goog-user-project: project-id" \ --data "{\"name\": {\"key-ring-name\": {}}}"
See the KeyRing.create
API documentation
for more information.
Create an asymmetric decryption key
Follow these steps to create an asymmetric decryption key on the specified key
ring and location. These examples use a software
protection level and an
rsa-decrypt-oaep-2048-sha256
When you first create the key, the key's initial version has a state of pending generation. When the state changes to enabled, you can use the key. To learn more about key version states, see Key states.
Web UI
Go to the Cryptographic Keys page in the Cloud Console.
Click the name of the key ring for which you will create a key.
Click Create key.
In the What type of key do you want to create?, choose Generated key.
In the Key name field, enter the name for your key.
Click the Protection level dropdown and select Software.
Click the Purpose dropdown and select Asymmetric decrypt.
Click the Algorithm dropdown and select 2048 bit RSA - OAEP Padding - SHA256 Digest. You can change this value on future key versions.
Click Create.
Command-line
To use Cloud KMS on the command line, first Install or upgrade to the latest version of Cloud SDK.
gcloud kms keys create key \ --keyring key-ring \ --location location \ --purpose "asymmetric-encryption" \ --default-algorithm "rsa-decrypt-oaep-2048-sha256"
Replace key with a name for the new key. Replace key-ring with the name of the existing key ring where the key will be located. Replace location with the Cloud KMS location for the key ring.
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.
Create an asymmetric decryption key by calling
CryptoKey.create
.
Create an asymmetric signing key
Follow these steps to create an asymmetric signing key on the specified key ring
and location. These examples use a software
protection level and an
rsa-sign-pkcs1-2048-sha256
When you first create the key, the key's initial version has a state of pending generation. When the state changes to enabled, you can use the key. To learn more about key version states, see Key states.
Web UI
Go to the Cryptographic Keys page in the Cloud Console.
Click the name of the key ring for which you will create a key.
Click Create key.
In the What type of key do you want to create?, choose Generated key.
In the Key name field, enter the name for your key.
Click the Protection level dropdown and select Software.
Click the Purpose dropdown and select Asymmetric sign.
Click the Algorithm dropdown and select 2048 bit RSA - PKCS#1 v1.5 padding - SHA256 Digest. You can change this value on future key versions.
Click Create.
Command-line
To use Cloud KMS on the command line, first Install or upgrade to the latest version of Cloud SDK.
gcloud kms keys create key \ --keyring key-ring \ --location location \ --purpose "asymmetric-signing" \ --default-algorithm "rsa-sign-pkcs1-2048-sha256"
Replace key with a name for the key. Replace key-ring with the name of the existing key ring where the key will be located. Replace location with the Cloud KMS location for the key ring.
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.
Create an asymmetric signing key by calling
CryptoKey.create
.
Control access to asymmetric keys
A signer or validator requires the appropriate permission or role on the asymmetric key.
For a user or service that will perform signing, grant the
cloudkms.cryptoKeyVersions.useToSign
permission on the asymmetric key.For a user or service that will retrieve the public key, grant the
cloudkms.cryptoKeyVersions.viewPublicKey
on the asymmetric key. The public key is required for signature validation.
Learn about permissions and roles in Cloud KMS release at Permissions and Roles.
What's next
- Learn about Creating and validating signatures.
- Learn about Encrypting and decrypting data with an RSA key.
- Learn about Retrieving a public key.