| 39 | const keyRingName = client.keyRingPath(projectId, locationId, keyRingId); |
| 40 | |
| 41 | async function createKeyForImport() { |
| 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 | // Optional: ensure that only imported versions may be added to this |
| 52 | // key. |
| 53 | importOnly: true, |
| 54 | }, |
| 55 | // Do not allow KMS to generate an initial version of this key. |
| 56 | skipInitialVersionCreation: true, |
| 57 | }); |
| 58 | |
| 59 | console.log(`Created key for import: ${key.name}`); |
| 60 | return key; |
| 61 | } |
| 62 | |
| 63 | return createKeyForImport(); |
| 64 | // [END kms_create_key_for_import] |