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

Function main

kms/verifyMac.js:17–67  ·  view source on GitHub ↗
(
  projectId = 'your-project-id',
  locationId = 'us-east1',
  keyRingId = 'my-key-ring',
  keyId = 'my-key',
  versionId = '123',
  data = Buffer.from('...'),
  signature = Buffer.from('...')
)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(
18 projectId = 'your-project-id',
19 locationId = 'us-east1',
20 keyRingId = 'my-key-ring',
21 keyId = 'my-key',
22 versionId = '123',
23 data = Buffer.from('...'),
24 signature = Buffer.from('...')
25) {
26 // [START kms_verify_mac]
27 //
28 // TODO(developer): Uncomment these variables before running the sample.
29 //
30 // const projectId = 'your-project-id';
31 // const locationId = 'us-east1';
32 // const keyRingId = 'my-key-ring';
33 // const keyId = 'my-key';
34 // const versionId = '123';
35 // const data = Buffer.from('...');
36 // const signature = Buffer.from('...');
37
38 // Imports the Cloud KMS library
39 const {KeyManagementServiceClient} = require('@google-cloud/kms');
40
41 // Instantiates a client
42 const client = new KeyManagementServiceClient();
43
44 // Build the version name
45 const versionName = client.cryptoKeyVersionPath(
46 projectId,
47 locationId,
48 keyRingId,
49 keyId,
50 versionId
51 );
52
53 async function verifyMac() {
54 // Verify the data with Cloud KMS
55 const [verifyResponse] = await client.macVerify({
56 name: versionName,
57 data: data,
58 mac: signature,
59 });
60
61 console.log(`Verified: ${verifyResponse.success}`);
62 return verifyResponse;
63 }
64
65 return verifyMac();
66 // [END kms_verify_mac]
67}
68module.exports.main = main;
69
70/* c8 ignore next 10 */

Callers 1

verifyMac.jsFile · 0.70

Calls 1

verifyMacFunction · 0.85

Tested by

no test coverage detected