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 theCryptographyAsyncClient
andCryptographyClient
, by callingbuildAsyncClient()
andbuildClient()
respectively It constructs an instance of the desired client.The minimal configuration options required by
cryptographyClientBuilder
to build aCryptographyAsyncClient
or aCryptographyClient
are acredential
and either aJSON Web Key
or aAzure Key Vault key identifier
.To ensure correct behavior when performing operations such as
Decrypt
,Unwrap
andVerify
, it is recommended to use aCryptographyAsyncClient
orCryptographyClient
created 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 custompolicies
and a customhttp client
can 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 pipeline
with customHttpPipelinePolicy
policies can be specified. It provides finer control over the construction ofCryptographyAsyncClient
andCryptographyClient
HttpPipeline 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
cryptographyClientBuilder
to buildCryptographyClient
arejsonWebKey
orAzure Key Vault key identifier
andcredential
.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 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.CryptographyAsyncClient
buildAsyncClient()
Creates aCryptographyAsyncClient
based on options set in the builder.CryptographyClient
buildClient()
Creates aCryptographyClient
based on options set in the builder.CryptographyClientBuilder
clientOptions(com.azure.core.util.ClientOptions clientOptions)
Sets theClientOptions
which enables various options to be set on the client.CryptographyClientBuilder
configuration(com.azure.core.util.Configuration configuration)
Sets the configuration store that is used during construction of the service client.CryptographyClientBuilder
credential(com.azure.core.credential.TokenCredential credential)
Sets the credential to use when authenticating HTTP requests.CryptographyClientBuilder
httpClient(com.azure.core.http.HttpClient client)
Sets the HTTP client to use for sending and receiving requests to and from the service.CryptographyClientBuilder
httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
Sets the logging configuration for HTTP requests and responses.CryptographyClientBuilder
jsonWebKey(JsonWebKey jsonWebKey)
Sets theJsonWebKey
to be used for local cryptography operations.CryptographyClientBuilder
keyIdentifier(String keyId)
Sets the Azure Key Vault key identifier of the JSON Web Key to be used for cryptography operations.CryptographyClientBuilder
pipeline(com.azure.core.http.HttpPipeline pipeline)
Sets the HTTP pipeline to use for the service client.CryptographyClientBuilder
retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
Sets theRetryPolicy
that is used when each request is sent.CryptographyClientBuilder
serviceVersion(CryptographyServiceVersion version)
Sets theCryptographyServiceVersion
that is used when making API requests.
-
-
-
Method Detail
-
buildClient
public CryptographyClient buildClient()
Creates aCryptographyClient
based on options set in the builder. Every timebuildClient()
is called, a new instance ofCryptographyClient
is created.If
jsonWebKey
is set, then all other builder settings are ignored.If
pipeline
is set, then thepipeline
andjsonWebKey identifier
are used to create theclient
. All other builder settings are ignored. Ifpipeline
is not set, then anAzure Key Vault credential
andJSON Web Key identifier
are required to build theclient
.- Returns:
- A
CryptographyClient
with the options set from the builder. - Throws:
IllegalStateException
- Ifcredential(TokenCredential)
isnull
orkeyIdentifier(String)
is empty ornull
.
-
buildAsyncClient
public CryptographyAsyncClient buildAsyncClient()
Creates aCryptographyAsyncClient
based on options set in the builder. Every timebuildAsyncClient()
is called, a new instance ofCryptographyAsyncClient
is created.If
jsonWebKey
is set, then all other builder settings are ignored.If
pipeline
is set, then thepipeline
andjsonWebKey identifier
) are used to create theasync client
. All other builder settings are ignored. Ifpipeline
is not set, then anAzure Key Vault credential
andJSON Web Key identifier
are required to build theasync client
.- Returns:
- A
CryptographyAsyncClient
with the options set from the builder. - Throws:
IllegalStateException
- Ifcredential(TokenCredential)
isnull
orkeyIdentifier(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
,Unwrap
andVerify
, it is recommended to use aCryptographyAsyncClient
orCryptographyClient
created for the specific key version that was used for the corresponding inverse operation:Encrypt
Wrap
, orSign
, respectively.- Parameters:
keyId
- The Azure Key Vault key identifier of the JSON Web Key stored in the key vault.- Returns:
- The updated
CryptographyClientBuilder
object. - Throws:
NullPointerException
- IfkeyId
isnull
.
-
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
CryptographyClientBuilder
object. - Throws:
NullPointerException
- Ifcredential
isnull
.
-
jsonWebKey
public CryptographyClientBuilder jsonWebKey(JsonWebKey jsonWebKey)
Sets theJsonWebKey
to be used for local cryptography operations.If
jsonWebKey
is provided, then all other builder settings are ignored.- Parameters:
jsonWebKey
- The JSON Web Key to be used for local cryptography operations.- Returns:
- The updated
CryptographyClientBuilder
object. - Throws:
NullPointerException
- IfjsonWebKey
isnull
.
-
httpLogOptions
public CryptographyClientBuilder httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
Sets the logging configuration for HTTP requests and responses.If
logLevel
is not provided, default value ofHttpLogDetailLevel.NONE
is set.- Parameters:
logOptions
- The logging configuration to use when sending and receiving HTTP requests/responses.- Returns:
- The updated
CryptographyClientBuilder
object.
-
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
- Thepolicy
to be added.- Returns:
- The updated
CryptographyClientBuilder
object. - Throws:
NullPointerException
- Ifpolicy
isnull
.
-
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
CryptographyClientBuilder
object.
-
pipeline
public CryptographyClientBuilder pipeline(com.azure.core.http.HttpPipeline pipeline)
Sets the HTTP pipeline to use for the service client. Ifpipeline
is 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
CryptographyClientBuilder
object.
-
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.NONE
to bypass using configuration settings during construction.- Parameters:
configuration
- The configuration store used to get configuration details.- Returns:
- The updated
CryptographyClientBuilder
object.
-
serviceVersion
public CryptographyClientBuilder serviceVersion(CryptographyServiceVersion version)
Sets theCryptographyServiceVersion
that 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
-CryptographyServiceVersion
of the service to be used when making requests.- Returns:
- The updated
CryptographyClientBuilder
object.
-
retryPolicy
public CryptographyClientBuilder retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
Sets theRetryPolicy
that is used when each request is sent. The default retry policy will be used in the pipeline, if not provided.- Parameters:
retryPolicy
- User'sRetryPolicy
applied to each request.- Returns:
- The updated
CryptographyClientBuilder
object.
-
clientOptions
public CryptographyClientBuilder clientOptions(com.azure.core.util.ClientOptions clientOptions)
Sets theClientOptions
which enables various options to be set on the client. For example setting anapplicationId
usingClientOptions.setApplicationId(String)
to configure theUserAgentPolicy
for telemetry/monitoring purposes.More About Azure Core: Telemetry policy
- Parameters:
clientOptions
- TheClientOptions
to be set on the client.- Returns:
- The updated
CryptographyClientBuilder
object.
-
-