This topic shows how to manually wrap a key before importing the key into Cloud KMS. You only need to follow the instructions in this topic if you do not want to use the Google Cloud CLI to automatically wrap the key before importing it. For an overview of the differences, refer to How key import works.
You can complete the steps in this topic in 5 to 10 minutes, not including the Before you begin steps.
Before you begin
Before you can wrap a key, you must complete the following prerequisites.
- Create a target key ring and key, and create an import job.
- Verify that your key is available locally and formatted correctly for import into Cloud KMS.
- Patch and recompile OpenSSL
Retrieve the wrapping key
This section shows how to retrieve the wrapping key from the import job you created in Before you begin. Using the Google Cloud console is recommended.
Console
Go to the Key Management page in the Google Cloud console.
Click the name of the key ring that contains your import job.
Click the Import Jobs tab at the top of the page.
Click More more_vert, then Download wrapping key in the pop-up menu.
gcloud
To verify that the import job is active, run the
gcloud kms import-jobs describe command:
gcloud kms import-jobs describe IMPORT_JOB \ --location LOCATION \ --keyring KEY_RING \ --format="value(state)"
state: ACTIVE
Run the following command to save the public key from the import job to
${HOME}/wrapping-key.pem
gcloud kms import-jobs describe \
--location=LOCATION \
--keyring=KEY_RING \
--format="value(publicKey.pem)" \
IMPORT_JOB > ${HOME}/wrapping-key.pem
REST
Call the
ImportJob.getmethod.Retrieve the public key via the
publicKeyfield of theImportJob.getresponse. This value is of typeWrappingPublicKey. Thepemfield of theWrappingPublicKeytype is the public key encoded in Privacy Enhanced Mail (PEM) format.
For more information about the PEM-encoded format, see RFC 7468, especially the General Considerations and Textual Encoding of Subject Public Key Info sections.
Set up environment variables
The OpenSSL commands require several file paths as input values. Define environment variables for the file paths to make it easier to run the commands. Make sure you have access to write to the directories you define below.
Set the
PUB_WRAPPING_KEYvariable to the full path to the wrapping key you downloaded from the import job. The wrapping key ends in.pem.PUB_WRAPPING_KEY="WRAPPING_KEY_PATH"
Set the
TARGET_KEYvariable to the full path to the unwrapped (target) key.TARGET_KEY=