@@ -51,10 +51,10 @@ function add_member_to_cryptokey_policy($projectId, $ring, $key, $member, $role,
51
51
$ client ->useApplicationDefaultCredentials ();
52
52
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
53
53
54
- // Create the Cloud KMS client
54
+ // Create the Cloud KMS client.
55
55
$ kms = new Google_Service_CloudKMS ($ client );
56
56
57
- // The resource name of the cryptokey .
57
+ // The resource name of the CryptoKey .
58
58
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s ' ,
59
59
$ projectId ,
60
60
$ location ,
@@ -71,7 +71,7 @@ function add_member_to_cryptokey_policy($projectId, $ring, $key, $member, $role,
71
71
]);
72
72
$ policy ->setBindings ($ bindings );
73
73
74
- // Set the new IAM Policy
74
+ // Set the new IAM Policy.
75
75
$ request = new Google_Service_CloudKMS_SetIamPolicyRequest (['policy ' => $ policy ]);
76
76
$ kms ->projects_locations_keyRings_cryptoKeys ->setIamPolicy (
77
77
$ parent ,
@@ -102,10 +102,10 @@ function add_member_to_keyring_policy($projectId, $ring, $member, $role, $locati
102
102
$ client ->useApplicationDefaultCredentials ();
103
103
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
104
104
105
- // Create the Cloud KMS client
105
+ // Create the Cloud KMS client.
106
106
$ kms = new Google_Service_CloudKMS ($ client );
107
107
108
- // The resource name of the cryptokey .
108
+ // The resource name of the KeyRing .
109
109
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s ' ,
110
110
$ projectId ,
111
111
$ location ,
@@ -121,7 +121,7 @@ function add_member_to_keyring_policy($projectId, $ring, $member, $role, $locati
121
121
]);
122
122
$ policy ->setBindings ($ bindings );
123
123
124
- // Set the new IAM Policy
124
+ // Set the new IAM Policy.
125
125
$ request = new Google_Service_CloudKMS_SetIamPolicyRequest (['policy ' => $ policy ]);
126
126
$ kms ->projects_locations_keyRings ->setIamPolicy (
127
127
$ parent ,
@@ -149,13 +149,13 @@ function create_cryptokey($projectId, $ring, $key, $location = 'global')
149
149
$ client ->useApplicationDefaultCredentials ();
150
150
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
151
151
152
- // Create the Cloud KMS client
152
+ // Create the Cloud KMS client.
153
153
$ kms = new Google_Service_CloudKMS ($ client );
154
154
155
155
// This will allow the API access to the key for encryption and decryption.
156
156
$ purpose = 'ENCRYPT_DECRYPT ' ;
157
157
158
- // The resource name of the keyring associated with the cryptokey .
158
+ // The resource name of the KeyRing associated with the CryptoKey .
159
159
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s ' ,
160
160
$ projectId ,
161
161
$ location ,
@@ -165,7 +165,7 @@ function create_cryptokey($projectId, $ring, $key, $location = 'global')
165
165
$ cryptoKey = new Google_Service_CloudKMS_CryptoKey ();
166
166
$ cryptoKey ->setPurpose ($ purpose );
167
167
168
- // create the key for your project
168
+ // Create the CryptoKey for your project.
169
169
$ newKey = $ kms ->projects_locations_keyRings_cryptoKeys ->create (
170
170
$ parent ,
171
171
$ cryptoKey ,
@@ -193,21 +193,21 @@ function create_cryptokey_version($projectId, $ring, $key, $location = 'global')
193
193
$ client ->useApplicationDefaultCredentials ();
194
194
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
195
195
196
- // Create the Cloud KMS client
196
+ // Create the Cloud KMS client.
197
197
$ kms = new Google_Service_CloudKMS ($ client );
198
198
199
199
// This will allow the API access to the key for encryption and decryption.
200
200
$ purpose = 'ENCRYPT_DECRYPT ' ;
201
201
202
- // The resource name of the keyring associated with the cryptokey .
202
+ // The resource name of the CryptoKey .
203
203
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s ' ,
204
204
$ projectId ,
205
205
$ location ,
206
206
$ ring ,
207
207
$ key
208
208
);
209
209
210
- // create the key for your project
210
+ // Create the CryptoKey version for your project.
211
211
$ cryptoKeyVersion = new Google_Service_CloudKMS_CryptoKeyVersion ();
212
212
$ newVersion = $ kms ->projects_locations_keyRings_cryptoKeys_cryptoKeyVersions
213
213
->create ($ parent , $ cryptoKeyVersion );
@@ -233,16 +233,16 @@ function create_keyring($projectId, $ring, $location = 'global')
233
233
$ client ->useApplicationDefaultCredentials ();
234
234
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
235
235
236
- // Create the Cloud KMS client
236
+ // Create the Cloud KMS client.
237
237
$ kms = new Google_Service_CloudKMS ($ client );
238
238
239
- // The resource name of the location associated with the keyring .
239
+ // The resource name of the location associated with the KeyRing .
240
240
$ parent = sprintf ('projects/%s/locations/%s ' ,
241
241
$ projectId ,
242
242
$ location
243
243
);
244
244
245
- // create the key for your project
245
+ // Create the KeyRing for your project.
246
246
$ keyRing = new Google_Service_CloudKMS_KeyRing ();
247
247
$ kms ->projects_locations_keyRings ->create (
248
248
$ parent ,
@@ -273,7 +273,7 @@ function encrypt($projectId, $ring, $key, $infile, $outfile, $location = 'global
273
273
$ client ->useApplicationDefaultCredentials ();
274
274
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
275
275
276
- // Create the Cloud KMS client
276
+ // Create the Cloud KMS client.
277
277
$ kms = new Google_Service_CloudKMS ($ client );
278
278
279
279
// The resource name of the cryptokey.
@@ -284,16 +284,16 @@ function encrypt($projectId, $ring, $key, $infile, $outfile, $location = 'global
284
284
$ key
285
285
);
286
286
287
- // This client library requires we base64 encode binary data .
287
+ // Use the KMS API to encrypt the text .
288
288
$ encoded = base64_encode (file_get_contents ($ infile ));
289
-
290
289
$ request = new Google_Service_CloudKMS_EncryptRequest ();
291
290
$ request ->setPlaintext ($ encoded );
292
291
$ response = $ kms ->projects_locations_keyRings_cryptoKeys ->encrypt (
293
292
$ name ,
294
293
$ request
295
294
);
296
295
296
+ // Write the encrypted text to a file.
297
297
file_put_contents ($ outfile , $ response ['ciphertext ' ]);
298
298
printf ('Saved encrypted text to %s ' . PHP_EOL , $ outfile );
299
299
}
@@ -318,7 +318,7 @@ function decrypt($projectId, $ring, $key, $infile, $outfile, $location = 'global
318
318
$ client ->useApplicationDefaultCredentials ();
319
319
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
320
320
321
- // Create the Cloud KMS client
321
+ // Create the Cloud KMS client.
322
322
$ kms = new Google_Service_CloudKMS ($ client );
323
323
324
324
// The resource name of the cryptokey.
@@ -329,19 +329,18 @@ function decrypt($projectId, $ring, $key, $infile, $outfile, $location = 'global
329
329
$ key
330
330
);
331
331
332
+ // Use the KMS API to decrypt the text.
332
333
$ ciphertext = file_get_contents ($ infile );
333
-
334
334
$ request = new Google_Service_CloudKMS_DecryptRequest ();
335
335
$ request ->setCiphertext ($ ciphertext );
336
336
$ response = $ kms ->projects_locations_keyRings_cryptoKeys ->decrypt (
337
337
$ name ,
338
338
$ request
339
339
);
340
340
341
- // The plaintext response comes back base64 encoded .
341
+ // Write the decrypted text to a file .
342
342
$ plaintext = base64_decode ($ response ['plaintext ' ]);
343
343
file_put_contents ($ outfile , $ plaintext );
344
-
345
344
printf ('Saved decrypted text to %s ' . PHP_EOL , $ outfile );
346
345
}
347
346
# [END decrypt]
@@ -364,10 +363,10 @@ function destroy_cryptokey_version($projectId, $ring, $key, $version, $location
364
363
$ client ->useApplicationDefaultCredentials ();
365
364
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
366
365
367
- // Create the Cloud KMS client
366
+ // Create the Cloud KMS client.
368
367
$ kms = new Google_Service_CloudKMS ($ client );
369
368
370
- // The resource name of the cryptokey version.
369
+ // The resource name of the CryptoKey version.
371
370
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s/cryptoKeyVersions/%s ' ,
372
371
$ projectId ,
373
372
$ location ,
@@ -376,7 +375,7 @@ function destroy_cryptokey_version($projectId, $ring, $key, $version, $location
376
375
$ version
377
376
);
378
377
379
- // destroy the cryptokey version
378
+ // Destroy the CryptoKey version.
380
379
$ request = new Google_Service_CloudKMS_DestroyCryptoKeyVersionRequest ();
381
380
$ kms ->projects_locations_keyRings_cryptoKeys_cryptoKeyVersions ->destroy (
382
381
$ parent ,
@@ -405,10 +404,10 @@ function restore_cryptokey_version($projectId, $ring, $key, $version, $location
405
404
$ client ->useApplicationDefaultCredentials ();
406
405
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
407
406
408
- // Create the Cloud KMS client
407
+ // Create the Cloud KMS client.
409
408
$ kms = new Google_Service_CloudKMS ($ client );
410
409
411
- // The resource name of the cryptokey version.
410
+ // The resource name of the CryptoKey version.
412
411
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s/cryptoKeyVersions/%s ' ,
413
412
$ projectId ,
414
413
$ location ,
@@ -417,7 +416,7 @@ function restore_cryptokey_version($projectId, $ring, $key, $version, $location
417
416
$ version
418
417
);
419
418
420
- // restore the cryptokey version
419
+ // Restore the CryptoKey version.
421
420
$ request = new Google_Service_CloudKMS_RestoreCryptoKeyVersionRequest ();
422
421
$ kms ->projects_locations_keyRings_cryptoKeys_cryptoKeyVersions ->restore (
423
422
$ parent ,
@@ -446,10 +445,10 @@ function disable_cryptokey_version($projectId, $ring, $key, $version, $location
446
445
$ client ->useApplicationDefaultCredentials ();
447
446
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
448
447
449
- // Create the Cloud KMS client
448
+ // Create the Cloud KMS client.
450
449
$ kms = new Google_Service_CloudKMS ($ client );
451
450
452
- // The resource name of the keyring associated with the cryptokey .
451
+ // The resource name of the KeyRing associated with the CryptoKey .
453
452
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s/cryptoKeyVersions/%s ' ,
454
453
$ projectId ,
455
454
$ location ,
@@ -458,7 +457,7 @@ function disable_cryptokey_version($projectId, $ring, $key, $version, $location
458
457
$ version
459
458
);
460
459
461
- // destroy the cryptokey version
460
+ // Disable the CryptoKey version.
462
461
$ cryptoKeyVersion = $ kms ->projects_locations_keyRings_cryptoKeys_cryptoKeyVersions
463
462
->get ($ parent );
464
463
$ cryptoKeyVersion ->setState ('DISABLED ' );
@@ -491,10 +490,10 @@ function enable_cryptokey_version($projectId, $ring, $key, $version, $location =
491
490
$ client ->useApplicationDefaultCredentials ();
492
491
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
493
492
494
- // Create the Cloud KMS client
493
+ // Create the Cloud KMS client.
495
494
$ kms = new Google_Service_CloudKMS ($ client );
496
495
497
- // The resource name of the keyring associated with the cryptokey .
496
+ // The resource name of the KeyRing associated with the CryptoKey .
498
497
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s/cryptoKeyVersions/%s ' ,
499
498
$ projectId ,
500
499
$ location ,
@@ -503,7 +502,7 @@ function enable_cryptokey_version($projectId, $ring, $key, $version, $location =
503
502
$ version
504
503
);
505
504
506
- // destroy the cryptokey version
505
+ // Enable the CryptoKey version.
507
506
$ cryptoKeyVersion = $ kms ->projects_locations_keyRings_cryptoKeys_cryptoKeyVersions
508
507
->get ($ parent );
509
508
$ cryptoKeyVersion ->setState ('ENABLED ' );
@@ -535,10 +534,10 @@ function get_cryptokey_policy($projectId, $ring, $key, $location = 'global')
535
534
$ client ->useApplicationDefaultCredentials ();
536
535
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
537
536
538
- // Create the Cloud KMS client
537
+ // Create the Cloud KMS client.
539
538
$ kms = new Google_Service_CloudKMS ($ client );
540
539
541
- // The resource name of the cryptokey .
540
+ // The resource name of the CryptoKey .
542
541
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s ' ,
543
542
$ projectId ,
544
543
$ location ,
@@ -573,7 +572,7 @@ function get_keyring_policy($projectId, $ring, $location = 'global')
573
572
$ client ->useApplicationDefaultCredentials ();
574
573
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
575
574
576
- // Create the Cloud KMS client
575
+ // Create the Cloud KMS client.
577
576
$ kms = new Google_Service_CloudKMS ($ client );
578
577
579
578
// The resource name of the location associated with the key rings.
@@ -610,16 +609,15 @@ function get_keyring_policy($projectId, $ring, $location = 'global')
610
609
*/
611
610
function remove_member_from_cryptokey_policy ($ projectId , $ ring , $ key , $ member , $ role , $ location = 'global ' )
612
611
{
613
- // Instantiate the client, authenticate using Application Default Credentials,
614
- // and add the scopes.
612
+ // Instantiate the client, authenticate, and add scopes.
615
613
$ client = new Google_Client ();
616
614
$ client ->useApplicationDefaultCredentials ();
617
615
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
618
616
619
- // Create the Cloud KMS client
617
+ // Create the Cloud KMS client.
620
618
$ kms = new Google_Service_CloudKMS ($ client );
621
619
622
- // The resource name of the keyring associated with the cryptokey .
620
+ // The resource name of the KeyRing associated with the CryptoKey .
623
621
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s ' ,
624
622
$ projectId ,
625
623
$ location ,
@@ -640,7 +638,7 @@ function remove_member_from_cryptokey_policy($projectId, $ring, $key, $member, $
640
638
}
641
639
}
642
640
643
- // Set the new IAM Policy
641
+ // Set the new IAM Policy.
644
642
$ request = new Google_Service_CloudKMS_SetIamPolicyRequest (['policy ' => $ policy ]);
645
643
$ kms ->projects_locations_keyRings_cryptoKeys ->setIamPolicy (
646
644
$ parent ,
@@ -675,10 +673,10 @@ function remove_member_from_keyring_policy($projectId, $ring, $member, $role, $l
675
673
$ client ->useApplicationDefaultCredentials ();
676
674
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
677
675
678
- // Create the Cloud KMS client
676
+ // Create the Cloud KMS client.
679
677
$ kms = new Google_Service_CloudKMS ($ client );
680
678
681
- // The resource name of the location associated with the keyring .
679
+ // The resource name of the location associated with the KeyRing .
682
680
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s ' ,
683
681
$ projectId ,
684
682
$ location ,
@@ -698,7 +696,7 @@ function remove_member_from_keyring_policy($projectId, $ring, $member, $role, $l
698
696
}
699
697
}
700
698
701
- // Set the new IAM Policy
699
+ // Set the new IAM Policy.
702
700
$ request = new Google_Service_CloudKMS_SetIamPolicyRequest (['policy ' => $ policy ]);
703
701
$ kms ->projects_locations_keyRings ->setIamPolicy (
704
702
$ parent ,
@@ -729,18 +727,18 @@ function set_cryptokey_primary_version($projectId, $ring, $key, $version, $locat
729
727
$ client ->useApplicationDefaultCredentials ();
730
728
$ client ->addScope ('https://www.googleapis.com/auth/cloud-platform ' );
731
729
732
- // Create the Cloud KMS client
730
+ // Create the Cloud KMS client.
733
731
$ kms = new Google_Service_CloudKMS ($ client );
734
732
735
- // The resource name of the keyring associated with the cryptokey .
733
+ // The resource name of the KeyRing associated with the CryptoKey .
736
734
$ parent = sprintf ('projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s ' ,
737
735
$ projectId ,
738
736
$ location ,
739
737
$ ring ,
740
738
$ key
741
739
);
742
740
743
- // Update the primary version.
741
+ // Update the CryptoKey primary version.
744
742
$ request = new Google_Service_CloudKMS_UpdateCryptoKeyPrimaryVersionRequest ();
745
743
$ request ->setCryptoKeyVersionId ($ version );
746
744
$ cryptoKey = $ kms ->projects_locations_keyRings_cryptoKeys ->updatePrimaryVersion (
0 commit comments