| 46 | ); |
| 47 | |
| 48 | async function getPublicKey() { |
| 49 | const [publicKey] = await client.getPublicKey({ |
| 50 | name: versionName, |
| 51 | }); |
| 52 | |
| 53 | // Optional, but recommended: perform integrity verification on publicKey. |
| 54 | // For more details on ensuring E2E in-transit integrity to and from Cloud KMS visit: |
| 55 | // https://cloud.google.com/kms/docs/data-integrity-guidelines |
| 56 | const crc32c = require('fast-crc32c'); |
| 57 | if (publicKey.name !== versionName) { |
| 58 | throw new Error('GetPublicKey: request corrupted in-transit'); |
| 59 | } |
| 60 | if (crc32c.calculate(publicKey.pem) !== Number(publicKey.pemCrc32c.value)) { |
| 61 | throw new Error('GetPublicKey: response corrupted in-transit'); |
| 62 | } |
| 63 | |
| 64 | console.log(`Public key pem: ${publicKey.pem}`); |
| 65 | |
| 66 | return publicKey; |
| 67 | } |
| 68 | |
| 69 | return getPublicKey(); |
| 70 | // [END kms_get_public_key] |