Class CryptographyClientBuilder
- java.lang.Object
-
- com.azure.security.keyvault.keys.cryptography.CryptographyClientBuilder
-
public final class CryptographyClientBuilder extends Object
This class provides a fluent builder API to help aid the configuration and instantiation of theCryptographyAsyncClientandCryptographyClient, by callingbuildAsyncClient()andbuildClient()respectively It constructs an instance of the desired client.The minimal configuration options required by
cryptographyClientBuilderto build aCryptographyAsyncClientor aCryptographyClientare acredentialand either aJSON Web Keyor aAzure Key Vault key identifier.To ensure correct behavior when performing operations such as
Decrypt,UnwrapandVerify, it is recommended to use aCryptographyAsyncClientorCryptographyClientcreated for the specific key version that was used for the corresponding inverse operation:Encrypt,Wrap, orSign, respectively.CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder() .keyIdentifier("<your-key-id>") .credential(new DefaultAzureCredentialBuilder().build()) .buildAsyncClient();JsonWebKey jsonWebKey = new JsonWebKey().setId("SampleJsonWebKey"); CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder() .jsonWebKey(jsonWebKey) .buildAsyncClient();The
log detail level, multiple custompoliciesand a customhttp clientcan be optionally configured in theCryptographyClientBuilder.CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder() .keyIdentifier("<your-key-id>") .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) .addPolicy(new KeyVaultCredentialPolicy(new DefaultAzureCredentialBuilder().build())) .httpClient(HttpClient.createDefault()) .buildAsyncClient();Alternatively, a custom
http pipelinewith customHttpPipelinePolicypolicies can be specified. It provides finer control over the construction ofCryptographyAsyncClientandCryptographyClientHttpPipeline pipeline = new HttpPipelineBuilder() .policies(new KeyVaultCredentialPolicy(new DefaultAzureCredentialBuilder().build()), new RetryPolicy()) .build(); CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder() .pipeline(pipeline) .keyIdentifier("<your-key-id>") .buildAsyncClient();The minimal configuration options required by
cryptographyClientBuilderto buildCryptographyClientarejsonWebKeyorAzure Key Vault key identifierandcredential.CryptographyClient cryptographyClient = new CryptographyClientBuilder() .keyIdentifier("<your-key-id>") .credential(new DefaultAzureCredentialBuilder().build()) .buildClient();JsonWebKey jsonWebKey = new JsonWebKey().setId("SampleJsonWebKey"); CryptographyClient cryptographyClient = new CryptographyClientBuilder() .jsonWebKey(jsonWebKey) .buildClient();- See Also:
CryptographyAsyncClient,CryptographyClient
-
-
Constructor Summary
Constructors Constructor Description CryptographyClientBuilder()The constructor with defaults.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CryptographyClientBuilderaddPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)Adds a policy to the set of existing policies that are executed after the client required policies.CryptographyAsyncClientbuildAsyncClient()Creates aCryptographyAsyncClientbased on options set in the builder.CryptographyClientbuildClient()Creates aCryptographyClientbased on options set in the builder.CryptographyClientBuilderclientOptions(com.azure.core.util.ClientOptions clientOptions)Sets theClientOptionswhich enables various options to be set on the client.CryptographyClientBuilderconfiguration(com.azure.core.util.Configuration configuration)Sets the configuration store that is used during construction of the service client.CryptographyClientBuildercredential(com.azure.core.credential.TokenCredential credential)Sets the credential to use when authenticating HTTP requests.CryptographyClientBuilderhttpClient(com.azure.core.http.HttpClient client)Sets the HTTP client to use for sending and receiving requests to and from the service.CryptographyClientBuilderhttpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)Sets the logging configuration for HTTP requests and responses.CryptographyClientBuilderjsonWebKey(JsonWebKey jsonWebKey)Sets theJsonWebKeyto be used for local cryptography operations.CryptographyClientBuilderkeyIdentifier(String keyId)Sets the Azure Key Vault key identifier of the JSON Web Key to be used for cryptography operations.CryptographyClientBuilderpipeline(com.azure.core.http.HttpPipeline pipeline)Sets the HTTP pipeline to use for the service client.CryptographyClientBuilderretryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)Sets theRetryPolicythat is used when each request is sent.CryptographyClientBuilderserviceVersion(CryptographyServiceVersion version)Sets theCryptographyServiceVersionthat is used when making API requests.
-
-
-
Method Detail
-
buildClient
public CryptographyClient buildClient()
Creates aCryptographyClientbased on options set in the builder. Every timebuildClient()is called, a new instance ofCryptographyClientis created.If
jsonWebKeyis set, then all other builder settings are ignored.If
pipelineis set, then thepipelineandjsonWebKey identifierare used to create theclient. All other builder settings are ignored. Ifpipelineis not set, then anAzure Key Vault credentialandJSON Web Key identifierare required to build theclient.- Returns:
- A
CryptographyClientwith the options set from the builder. - Throws:
IllegalStateException- Ifcredential(TokenCredential)isnullorkeyIdentifier(String)is empty ornull.
-
buildAsyncClient
public CryptographyAsyncClient buildAsyncClient()
Creates aCryptographyAsyncClientbased on options set in the builder. Every timebuildAsyncClient()is called, a new instance ofCryptographyAsyncClientis created.If
jsonWebKeyis set, then all other builder settings are ignored.If
pipelineis set, then thepipelineandjsonWebKey identifier) are used to create theasync client. All other builder settings are ignored. Ifpipelineis not set, then anAzure Key Vault credentialandJSON Web Key identifierare required to build theasync client.- Returns:
- A
CryptographyAsyncClientwith the options set from the builder. - Throws:
IllegalStateException- Ifcredential(TokenCredential)isnullorkeyIdentifier(String)is empty ornull.
-
keyIdentifier
public CryptographyClientBuilder keyIdentifier(String keyId)
Sets the Azure Key Vault key identifier of the JSON Web Key to be used for cryptography operations.To ensure correct behavior when performing operations such as
Decrypt,UnwrapandVerify, it is recommended to use aCryptographyAsyncClientorCryptographyClientcreated for the specific key version that was used for the corresponding inverse operation:EncryptWrap, orSign, respectively.- Parameters:
keyId- The Azure Key Vault key identifier of the JSON Web Key stored in the key vault.- Returns:
- The updated
CryptographyClientBuilderobject. - Throws:
NullPointerException- IfkeyIdisnull.
-
credential
public CryptographyClientBuilder credential(com.azure.core.credential.TokenCredential credential)
Sets the credential to use when authenticating HTTP requests.- Parameters:
credential- The credential to use for authenticating HTTP requests.- Returns:
- The updated
CryptographyClientBuilderobject. - Throws:
NullPointerException- Ifcredentialisnull.
-
jsonWebKey
public CryptographyClientBuilder jsonWebKey(JsonWebKey jsonWebKey)
Sets theJsonWebKeyto be used for local cryptography operations.If
jsonWebKeyis provided, then all other builder settings are ignored.- Parameters:
jsonWebKey- The JSON Web Key to be used for local cryptography operations.- Returns:
- The updated
CryptographyClientBuilderobject. - Throws:
NullPointerException- IfjsonWebKeyisnull.
-
httpLogOptions
public CryptographyClientBuilder httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
Sets the logging configuration for HTTP requests and responses.If
logLevelis not provided, default value ofHttpLogDetailLevel.NONEis set.- Parameters:
logOptions- The logging configuration to use when sending and receiving HTTP requests/responses.- Returns:
- The updated
CryptographyClientBuilderobject.
-
addPolicy
public CryptographyClientBuilder addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
Adds a policy to the set of existing policies that are executed after the client required policies.- Parameters:
policy- Thepolicyto be added.- Returns:
- The updated
CryptographyClientBuilderobject. - Throws:
NullPointerException- Ifpolicyisnull.
-
httpClient
public CryptographyClientBuilder httpClient(com.azure.core.http.HttpClient client)
Sets the HTTP client to use for sending and receiving requests to and from the service.- Parameters:
client- The HTTP client to use for requests.- Returns:
- The updated
CryptographyClientBuilderobject.
-
pipeline
public CryptographyClientBuilder pipeline(com.azure.core.http.HttpPipeline pipeline)
Sets the HTTP pipeline to use for the service client. Ifpipelineis set, all other settings are ignored, aside fromJSON Web Key identifier.- Parameters:
pipeline- The HTTP pipeline to use for sending service requests and receiving responses.- Returns:
- The updated
CryptographyClientBuilderobject.
-
configuration
public CryptographyClientBuilder configuration(com.azure.core.util.Configuration configuration)
Sets the configuration store that is used during construction of the service client. The default configuration store is a clone of theglobal configuration store, useConfiguration.NONEto bypass using configuration settings during construction.- Parameters:
configuration- The configuration store used to get configuration details.- Returns:
- The updated
CryptographyClientBuilderobject.
-
serviceVersion
public CryptographyClientBuilder serviceVersion(CryptographyServiceVersion version)
Sets theCryptographyServiceVersionthat is used when making API requests.If a service version is not provided, the service version that will be used will be the latest known service version based on the version of the client library being used. If no service version is specified, updating to a newer version the client library will have the result of potentially moving to a newer service version.
- Parameters:
version-CryptographyServiceVersionof the service to be used when making requests.- Returns:
- The updated
CryptographyClientBuilderobject.
-
retryPolicy
public CryptographyClientBuilder retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
Sets theRetryPolicythat is used when each request is sent. The default retry policy will be used in the pipeline, if not provided.- Parameters:
retryPolicy- User'sRetryPolicyapplied to each request.- Returns:
- The updated
CryptographyClientBuilderobject.
-
clientOptions
public CryptographyClientBuilder clientOptions(com.azure.core.util.ClientOptions clientOptions)
Sets theClientOptionswhich enables various options to be set on the client. For example setting anapplicationIdusingClientOptions.setApplicationId(String)to configure theUserAgentPolicyfor telemetry/monitoring purposes.More About Azure Core: Telemetry policy
- Parameters:
clientOptions- TheClientOptionsto be set on the client.- Returns:
- The updated
CryptographyClientBuilderobject.
-
-