/** * * * <pre> * The list of [CryptoKeys][google.cloud.kms.v1.CryptoKey]. * </pre> * * <code>repeated .google.cloud.kms.v1.CryptoKey crypto_keys = 1;</code> */ public Builder addCryptoKeys( int index, com.google.cloud.kms.v1.CryptoKey.Builder builderForValue) { if (cryptoKeysBuilder_ == null) { ensureCryptoKeysIsMutable(); cryptoKeys_.add(index, builderForValue.build()); onChanged(); } else { cryptoKeysBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
input.readMessage(com.google.cloud.kms.v1.CryptoKey.parser(), extensionRegistry); if (subBuilder != null) { subBuilder.mergeFrom(cryptoKey_); cryptoKey_ = subBuilder.buildPartial();
/** * * * <pre> * Output only. The time at which this [CryptoKey][google.cloud.kms.v1.CryptoKey] was created. * </pre> * * <code>.google.protobuf.Timestamp create_time = 5;</code> */ private com.google.protobuf.SingleFieldBuilderV3< com.google.protobuf.Timestamp, com.google.protobuf.Timestamp.Builder, com.google.protobuf.TimestampOrBuilder> getCreateTimeFieldBuilder() { if (createTimeBuilder_ == null) { createTimeBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< com.google.protobuf.Timestamp, com.google.protobuf.Timestamp.Builder, com.google.protobuf.TimestampOrBuilder>( getCreateTime(), getParentForChildren(), isClean()); createTime_ = null; } return createTimeBuilder_; }
input.readMessage(com.google.cloud.kms.v1.CryptoKey.parser(), extensionRegistry); if (subBuilder != null) { subBuilder.mergeFrom(cryptoKey_); cryptoKey_ = subBuilder.buildPartial();
input.readMessage(com.google.cloud.kms.v1.CryptoKey.parser(), extensionRegistry); if (subBuilder != null) { subBuilder.mergeFrom(cryptoKey_); cryptoKey_ = subBuilder.buildPartial();
/** * * * <pre> * A [CryptoKey][google.cloud.kms.v1.CryptoKey] with initial field values. * </pre> * * <code>.google.cloud.kms.v1.CryptoKey crypto_key = 3;</code> */ public Builder mergeCryptoKey(com.google.cloud.kms.v1.CryptoKey value) { if (cryptoKeyBuilder_ == null) { if (cryptoKey_ != null) { cryptoKey_ = com.google.cloud.kms.v1.CryptoKey.newBuilder(cryptoKey_) .mergeFrom(value) .buildPartial(); } else { cryptoKey_ = value; } onChanged(); } else { cryptoKeyBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * [CryptoKey][google.cloud.kms.v1.CryptoKey] with updated values. * </pre> * * <code>.google.cloud.kms.v1.CryptoKey crypto_key = 1;</code> */ public Builder mergeCryptoKey(com.google.cloud.kms.v1.CryptoKey value) { if (cryptoKeyBuilder_ == null) { if (cryptoKey_ != null) { cryptoKey_ = com.google.cloud.kms.v1.CryptoKey.newBuilder(cryptoKey_) .mergeFrom(value) .buildPartial(); } else { cryptoKey_ = value; } onChanged(); } else { cryptoKeyBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * Output only. The time at which this [CryptoKey][google.cloud.kms.v1.CryptoKey] was created. * </pre> * * <code>.google.protobuf.Timestamp create_time = 5;</code> */ private com.google.protobuf.SingleFieldBuilderV3< com.google.protobuf.Timestamp, com.google.protobuf.Timestamp.Builder, com.google.protobuf.TimestampOrBuilder> getCreateTimeFieldBuilder() { if (createTimeBuilder_ == null) { createTimeBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< com.google.protobuf.Timestamp, com.google.protobuf.Timestamp.Builder, com.google.protobuf.TimestampOrBuilder>( getCreateTime(), getParentForChildren(), isClean()); createTime_ = null; } return createTimeBuilder_; }
/** * * * <pre> * The list of [CryptoKeys][google.cloud.kms.v1.CryptoKey]. * </pre> * * <code>repeated .google.cloud.kms.v1.CryptoKey crypto_keys = 1;</code> */ public Builder addCryptoKeys( int index, com.google.cloud.kms.v1.CryptoKey.Builder builderForValue) { if (cryptoKeysBuilder_ == null) { ensureCryptoKeysIsMutable(); cryptoKeys_.add(index, builderForValue.build()); onChanged(); } else { cryptoKeysBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * The list of [CryptoKeys][google.cloud.kms.v1.CryptoKey]. * </pre> * * <code>repeated .google.cloud.kms.v1.CryptoKey crypto_keys = 1;</code> */ public Builder setCryptoKeys( int index, com.google.cloud.kms.v1.CryptoKey.Builder builderForValue) { if (cryptoKeysBuilder_ == null) { ensureCryptoKeysIsMutable(); cryptoKeys_.set(index, builderForValue.build()); onChanged(); } else { cryptoKeysBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * The list of [CryptoKeys][google.cloud.kms.v1.CryptoKey]. * </pre> * * <code>repeated .google.cloud.kms.v1.CryptoKey crypto_keys = 1;</code> */ public Builder addCryptoKeys(com.google.cloud.kms.v1.CryptoKey.Builder builderForValue) { if (cryptoKeysBuilder_ == null) { ensureCryptoKeysIsMutable(); cryptoKeys_.add(builderForValue.build()); onChanged(); } else { cryptoKeysBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * * * <pre> * [CryptoKey][google.cloud.kms.v1.CryptoKey] with updated values. * </pre> * * <code>.google.cloud.kms.v1.CryptoKey crypto_key = 1;</code> */ public Builder setCryptoKey(com.google.cloud.kms.v1.CryptoKey.Builder builderForValue) { if (cryptoKeyBuilder_ == null) { cryptoKey_ = builderForValue.build(); onChanged(); } else { cryptoKeyBuilder_.setMessage(builderForValue.build()); } return this; } /**
/** * * * <pre> * A [CryptoKey][google.cloud.kms.v1.CryptoKey] with initial field values. * </pre> * * <code>.google.cloud.kms.v1.CryptoKey crypto_key = 3;</code> */ public Builder setCryptoKey(com.google.cloud.kms.v1.CryptoKey.Builder builderForValue) { if (cryptoKeyBuilder_ == null) { cryptoKey_ = builderForValue.build(); onChanged(); } else { cryptoKeyBuilder_.setMessage(builderForValue.build()); } return this; } /**
/** * * * <pre> * Output only. The time at which this [CryptoKey][google.cloud.kms.v1.CryptoKey] was created. * </pre> * * <code>.google.protobuf.Timestamp create_time = 5;</code> */ public com.google.protobuf.Timestamp.Builder getCreateTimeBuilder() { onChanged(); return getCreateTimeFieldBuilder().getBuilder(); } /**
@java.lang.Override public com.google.cloud.kms.v1.CryptoKey build() { com.google.cloud.kms.v1.CryptoKey result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
/** Use {@link #getLabelsMap()} instead. */ @java.lang.Deprecated public java.util.Map<java.lang.String, java.lang.String> getLabels() { return getLabelsMap(); } /**
@java.lang.Override protected Builder newBuilderForType(com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**
/** * Creates an RSA encrypt/decrypt key pair with the given id. */ public static CryptoKey createAsymmetricKey(String projectId, String locationId, String keyRingId, String cryptoKeyId) throws IOException { try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) { String parent = KeyRingName.format(projectId, locationId, keyRingId); CryptoKeyPurpose purpose = CryptoKeyPurpose.ASYMMETRIC_DECRYPT; CryptoKeyVersionAlgorithm algorithm = CryptoKeyVersionAlgorithm.RSA_DECRYPT_OAEP_2048_SHA256; CryptoKeyVersionTemplate version = CryptoKeyVersionTemplate.newBuilder() .setAlgorithm(algorithm) .build(); CryptoKey cryptoKey = CryptoKey.newBuilder() .setPurpose(purpose) .setVersionTemplate(version) .build(); CryptoKey createdKey = client.createCryptoKey(parent, cryptoKeyId, cryptoKey); return createdKey; } } // [END kms_create_asymmetric_key]
/** * Creates a new crypto key with the given id. */ public static CryptoKey createCryptoKey(String projectId, String locationId, String keyRingId, String cryptoKeyId) throws IOException { // Create the Cloud KMS client. try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) { // The resource name of the location associated with the KeyRing. String parent = KeyRingName.format(projectId, locationId, keyRingId); // This will allow the API access to the key for encryption and decryption. CryptoKey cryptoKey = CryptoKey.newBuilder() .setPurpose(CryptoKeyPurpose.ENCRYPT_DECRYPT) .build(); // Create the CryptoKey for your project. CryptoKey createdKey = client.createCryptoKey(parent, cryptoKeyId, cryptoKey); return createdKey; } } // [END kms_create_cryptokey]