Download and install Google Cloud SDK
Follow the Google instructions (https://cloud.google.com/sdk/docs/install) to download, install, and configure Google Cloud SDK.Encrypt a test file
Before proceeding with the next two steps, ensure the GCP user that is calling the encrypt and decrypt methods has the cloudkms.cryptoKeyVersions.useToEncrypt and cloudkms.cryptoKeyVersions.useToDecrypt permissions on the key used to encrypt or decrypt. One way to permit a user to encrypt or decrypt is to add the user to the roles/cloudkms.cryptoKeyEncrypter, roles/cloudkms.cryptoKeyDecrypter, or roles/cloudkms.cryptoKeyEncrypterDecrypter IAM roles for that key. For more information, see Permissions and Roles.
Run the following gcloud kms command to encrypt a test file by using the externally managed key:
- Replace
[key]with the name of the key to use for encryption. - Replace
[key-ring]with the name of the key ring where the key is located. - Replace
[location]with the Cloud KMS location for the key ring. - Replace
[file-with-data-to-encrypt]and[file-to-store-encrypted-data]with the local file paths for reading the plaintext data and saving the encrypted output.
If the command succeeds, it returns no output.
Decrypt a test file
Perform the following steps to decrypt a test file by using the externally managed key:Run the following gcloud kms command with the externally managed key to decrypt the file that you encrypted in the previous step.
- Replace
[key]with the name of the key to use for decryption. - Replace
[key-ring]with the name of the key ring where the key is located. - Replace
[location]with the Cloud KMS location for the key ring. - Replace
[file-path-with-encrypted-data]and[file-path-to-store-plaintext]with the local file paths for reading the encrypted data and saving the decrypted output.
If the command succeeds, it returns no output.

