MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

kms/createKeySymmetricEncryptDecrypt.js:17–59  ·  view source on GitHub ↗
(
  projectId = 'my-project',
  locationId = 'us-east1',
  keyRingId = 'my-key-ring',
  id = 'my-symmetric-encryption-key'
)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(
18 projectId = 'my-project',
19 locationId = 'us-east1',
20 keyRingId = 'my-key-ring',
21 id = 'my-symmetric-encryption-key'
22) {
23 // [START kms_create_key_symmetric_encrypt_decrypt]
24 //
25 // TODO(developer): Uncomment these variables before running the sample.
26 //
27 // const projectId = 'my-project';
28 // const locationId = 'us-east1';
29 // const keyRingId = 'my-key-ring';
30 // const id = 'my-symmetric-encryption-key';
31
32 // Imports the Cloud KMS library
33 const {KeyManagementServiceClient} = require('@google-cloud/kms');
34
35 // Instantiates a client
36 const client = new KeyManagementServiceClient();
37
38 // Build the parent key ring name
39 const keyRingName = client.keyRingPath(projectId, locationId, keyRingId);
40
41 async function createKeySymmetricEncryptDecrypt() {
42 const [key] = await client.createCryptoKey({
43 parent: keyRingName,
44 cryptoKeyId: id,
45 cryptoKey: {
46 purpose: 'ENCRYPT_DECRYPT',
47 versionTemplate: {
48 algorithm: 'GOOGLE_SYMMETRIC_ENCRYPTION',
49 },
50 },
51 });
52
53 console.log(`Created symmetric key: ${key.name}`);
54 return key;
55 }
56
57 return createKeySymmetricEncryptDecrypt();
58 // [END kms_create_key_symmetric_encrypt_decrypt]
59}
60module.exports.main = main;
61
62/* c8 ignore next 10 */

Calls 1

Tested by

no test coverage detected