Skip to content

Instantly share code, notes, and snippets.

@rhyskentish
Last active May 18, 2020 16:03
Show Gist options
  • Select an option

  • Save rhyskentish/01752b64823ff1f54557875c18c44a25 to your computer and use it in GitHub Desktop.

Select an option

Save rhyskentish/01752b64823ff1f54557875c18c44a25 to your computer and use it in GitHub Desktop.
const { KeyManagementServiceClient } = require('@google-cloud/kms');
const projectId = <YourProjectID>;
const locationId = <YourPreferedStorageLocationID>; //Based on the google cloud regions e.g. us-central1
const keyRingId = <KeyRingID>;
const keyId = <YourKeyId>;
const kmsClient = new KeyManagementServiceClient();
const locationName = kmsClient.locationPath(projectId, locationId);
async function createKeySymmetricEncryptDecrypt() {
const keyRingName = await kmsClient.keyRingPath(projectId, locationId, keyRingId);
const [key] = await kmsClient.createCryptoKey({
parent: keyRingName,
cryptoKeyId: keyId,
cryptoKey: {
purpose: 'ENCRYPT_DECRYPT',
versionTemplate: {
algorithm: 'GOOGLE_SYMMETRIC_ENCRYPTION',
},
},
});
console.log(`Created symmetric key: ${key.name}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment