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

Function main

kms/createKeyHsm.js:17–64  ·  view source on GitHub ↗
(
  projectId = 'my-project',
  locationId = 'us-east1',
  keyRingId = 'my-key-ring',
  id = 'my-hsm-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-hsm-encryption-key'
22) {
23 // [START kms_create_key_hsm]
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-hsm-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 createKeyHsm() {
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 protectionLevel: 'HSM',
50 },
51
52 // Optional: customize how long key versions should be kept before
53 // destroying.
54 destroyScheduledDuration: {seconds: 60 * 60 * 24},
55 },
56 });
57
58 console.log(`Created hsm key: ${key.name}`);
59 return key;
60 }
61
62 return createKeyHsm();
63 // [END kms_create_key_hsm]
64}
65module.exports.main = main;
66
67/* c8 ignore next 10 */

Callers 1

createKeyHsm.jsFile · 0.70

Calls 1

createKeyHsmFunction · 0.85

Tested by

no test coverage detected