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

Function decryptSymmetric

kms/decryptSymmetric.js:48–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46 const ciphertextCrc32c = crc32c.calculate(ciphertext);
47
48 async function decryptSymmetric() {
49 const [decryptResponse] = await client.decrypt({
50 name: keyName,
51 ciphertext: ciphertext,
52 ciphertextCrc32c: {
53 value: ciphertextCrc32c,
54 },
55 });
56
57 // Optional, but recommended: perform integrity verification on decryptResponse.
58 // For more details on ensuring E2E in-transit integrity to and from Cloud KMS visit:
59 // https://cloud.google.com/kms/docs/data-integrity-guidelines
60 if (
61 crc32c.calculate(decryptResponse.plaintext) !==
62 Number(decryptResponse.plaintextCrc32c.value)
63 ) {
64 throw new Error('Decrypt: response corrupted in-transit');
65 }
66
67 const plaintext = decryptResponse.plaintext.toString();
68
69 console.log(`Plaintext: ${plaintext}`);
70 return plaintext;
71 }
72
73 return decryptSymmetric();
74 // [END kms_decrypt_symmetric]

Callers 1

mainFunction · 0.85

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected