19
19
// [START kms_create_key_for_import]
20
20
import com .google .cloud .kms .v1 .CreateCryptoKeyRequest ;
21
21
import com .google .cloud .kms .v1 .CryptoKey ;
22
+ import com .google .cloud .kms .v1 .CryptoKey .CryptoKeyPurpose ;
23
+ import com .google .cloud .kms .v1 .CryptoKeyVersion .CryptoKeyVersionAlgorithm ;
22
24
import com .google .cloud .kms .v1 .CryptoKeyVersionTemplate ;
23
25
import com .google .cloud .kms .v1 .KeyManagementServiceClient ;
24
26
import com .google .cloud .kms .v1 .KeyRingName ;
25
27
import com .google .cloud .kms .v1 .ProtectionLevel ;
26
- import com .google .cloud .kms .v1 .CryptoKey .CryptoKeyPurpose ;
27
- import com .google .cloud .kms .v1 .CryptoKeyVersion .CryptoKeyVersionAlgorithm ;
28
-
29
28
import java .io .IOException ;
30
29
31
30
public class CreateKeyForImport {
@@ -40,8 +39,7 @@ public void createKeyForImport() throws IOException {
40
39
}
41
40
42
41
// Create a new crypto key to hold imported key versions.
43
- public void createKeyForImport (String projectId , String locationId ,
44
- String keyRingId , String id )
42
+ public void createKeyForImport (String projectId , String locationId , String keyRingId , String id )
45
43
throws IOException {
46
44
// Initialize client that will be used to send requests. This client only
47
45
// needs to be created once, and can be reused for multiple requests. After
@@ -52,24 +50,26 @@ public void createKeyForImport(String projectId, String locationId,
52
50
KeyRingName keyRingName = KeyRingName .of (projectId , locationId , keyRingId );
53
51
54
52
// Create the crypto key.
55
- CryptoKey createdKey = client .createCryptoKey (
56
- CreateCryptoKeyRequest .newBuilder ()
57
- .setParent (keyRingName .toString ())
58
- .setCryptoKeyId (id )
59
- .setCryptoKey (CryptoKey .newBuilder ()
60
- .setPurpose (CryptoKeyPurpose .ASYMMETRIC_SIGN )
61
- .setVersionTemplate (
62
- CryptoKeyVersionTemplate .newBuilder ()
63
- .setProtectionLevel (ProtectionLevel .HSM )
64
- .setAlgorithm (CryptoKeyVersionAlgorithm .EC_SIGN_P256_SHA256 ))
65
- // Ensure that only imported versions may be
66
- // added to this key.
67
- .setImportOnly (true ))
68
- .setSkipInitialVersionCreation (true )
69
- .build ());
53
+ CryptoKey createdKey =
54
+ client .createCryptoKey (
55
+ CreateCryptoKeyRequest .newBuilder ()
56
+ .setParent (keyRingName .toString ())
57
+ .setCryptoKeyId (id )
58
+ .setCryptoKey (
59
+ CryptoKey .newBuilder ()
60
+ .setPurpose (CryptoKeyPurpose .ASYMMETRIC_SIGN )
61
+ .setVersionTemplate (
62
+ CryptoKeyVersionTemplate .newBuilder ()
63
+ .setProtectionLevel (ProtectionLevel .HSM )
64
+ .setAlgorithm (CryptoKeyVersionAlgorithm .EC_SIGN_P256_SHA256 ))
65
+ // Ensure that only imported versions may be
66
+ // added to this key.
67
+ .setImportOnly (true ))
68
+ .setSkipInitialVersionCreation (true )
69
+ .build ());
70
70
71
71
System .out .printf ("Created crypto key %s%n" , createdKey .getName ());
72
72
}
73
73
}
74
74
}
75
- // [END kms_create_crypto_key ]
75
+ // [END kms_create_key_for_import ]
0 commit comments