| 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] |