Skip to content

Instantly share code, notes, and snippets.

@rhyskentish
Created May 18, 2020 15:52
Show Gist options
  • Save rhyskentish/2061ba1e3f38c879ac8ea64c54d949bd to your computer and use it in GitHub Desktop.
Save rhyskentish/2061ba1e3f38c879ac8ea64c54d949bd to your computer and use it in GitHub Desktop.
const projectId = <YourProjectID>;
const locationId = <YourPreferedStorageLocationID>; //Based on the google cloud regions e.g. us-central1
const keyRingId = <KeyRingID>;
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: <YourKeyId>,
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