Stay organized with collections Save and categorize content based on your preferences.
Create encryption keys with Cloud KMSThis quickstart shows you how to create and use encryption keys with Cloud Key Management Service in a project you own. These instructions use the Google Cloud console to create key rings, keys, and key versions in Cloud KMS. For instructions that use other methods, see How-to guides.
This quickstart uses the command line to send requests to the Cloud KMS API. For programming examples that use the client libraries to send requests to the Cloud KMS API, see Encrypting and Decrypting.
Before you beginIn the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Verify that billing is enabled for your Google Cloud project.
Enable the Cloud KMS API.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloud init
To encrypt and decrypt content you will need a Cloud KMS key, which is part of a key ring.
Create a key ring named test
, and a key named quickstart
. Refer to the object hierarchy overview for more information about these objects and how they are related.
gcloud kms keyrings create "test" \
--location "global"
gcloud kms keys create "quickstart" \
--location "global" \
--keyring "test" \
--purpose "encryption"
You can use the list
option to view the name and metadata for the key that you just created.
gcloud kms keys list \
--location "global" \
--keyring "test"
You should see:
NAME PURPOSE PRIMARY_STATE projects/PROJECT_ID/locations/global/keyRings/test/cryptoKeys/quickstart ENCRYPT_DECRYPT ENABLEDEncrypt data
Now that you have a key, you can use that key to encrypt text or binary content.
Store some text to be encrypted in a file called "mysecret.txt".
echo -n "Some text to be encrypted" > mysecret.txt
To encrypt the data with gcloud kms encrypt
, provide your key information, specify the name of the plaintext file to encrypt, and specify the name of the file that will contain the encrypted content:
gcloud kms encrypt \
--location "global" \
--keyring "test" \
--key "quickstart" \
--plaintext-file ./mysecret.txt \
--ciphertext-file ./mysecret.txt.encrypted
The encrypt
method saves your encrypted content in the file specified by the --ciphertext-file
flag.
To decrypt the data with gcloud kms decrypt
, provide your key information, specify the name of the encrypted file (ciphertext file) to decrypt, and specify the name of the file that will contain the decrypted content:
gcloud kms decrypt \
--location "global" \
--keyring "test" \
--key "quickstart" \
--ciphertext-file ./mysecret.txt.encrypted \
--plaintext-file ./mysecret.txt.decrypted
The decrypt
method saves your decrypted content in the file specified by the --plaintext-file
flag.
To decrypt encrypted content, you must use the same key that was used to encrypt the content.
Clean upTo avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
List the versions available for your key:
gcloud kms keys versions list \
--location "global" \
--keyring "test" \
--key "quickstart"
To destroy a version, run the following command, where 1
is the number of the key version that you want to destroy:
gcloud kms keys versions destroy 1 \ --location "global" \ --keyring "test" \ --key "quickstart"What's next
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-13 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-13 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4