你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

CryptographyClientBuilder 类

  • java.lang.Object
    • com.azure.security.keyvault.keys.cryptography.CryptographyClientBuilder

实现

public final class CryptographyClientBuilder
implements TokenCredentialTrait<CryptographyClientBuilder>, HttpTrait<CryptographyClientBuilder>, ConfigurationTrait<CryptographyClientBuilder>

此类提供 Fluent builder API,通过分别调用 buildAsyncClient() 和 帮助配置和CryptographyClientbuildClient()实例化CryptographyAsyncClient,并分别构造所需客户端的实例。

生成 或 所需的CryptographyClientBuilder最小配置选项是 TokenCredentialJsonWebKeyAzure Key Vault key identifierCryptographyClientCryptographyAsyncClient

若要确保在执行 、 和 VerifyUnwrapDecrypt操作时的行为正确,建议分别为用于相应逆运算的特定密钥版本使用 CryptographyAsyncClientCryptographyClient 创建的 :EncryptWrapSign

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();

log detail level可以选择在 中CryptographyClientBuilder配置 、多个自定义policies和自定义 HttpClient

CryptographyAsyncClient cryptographyAsyncClient = new CryptographyClientBuilder()
     .keyIdentifier("<your-key-id>")
     .credential(new DefaultAzureCredentialBuilder().build())
     .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
     .httpClient(HttpClient.createDefault())
     .buildAsyncClient();

生成所需的CryptographyClientBuilder最小配置选项为 JsonWebKeyAzure Key Vault key identifierTokenCredentialCryptographyClient

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();

构造函数摘要

构造函数 说明
CryptographyClientBuilder()

具有默认值的构造函数。

方法摘要

修饰符和类型 方法和描述
CryptographyClientBuilder addPolicy(HttpPipelinePolicy policy)

添加 , HttpPipelinePolicy 以应用于发送的每个请求。

CryptographyAsyncClient buildAsyncClient()

CryptographyAsyncClient基于生成器中设置的选项创建 。

CryptographyClient buildClient()

CryptographyClient基于生成器中设置的选项创建 。

CryptographyClientBuilder clientOptions(ClientOptions clientOptions)

允许设置常见属性,例如应用程序 ID、标头、代理配置等。

CryptographyClientBuilder configuration(Configuration configuration)

设置在构造服务客户端期间使用的配置存储。

CryptographyClientBuilder credential(TokenCredential credential)

TokenCredential设置用于授权发送到服务的请求的 。

CryptographyClientBuilder disableChallengeResourceVerification()

禁用验证身份验证质询资源是否与密钥保管库或托管 HSM 域匹配。

CryptographyClientBuilder httpClient(HttpClient client)

HttpClient设置用于向/从服务发送和接收请求的 。

CryptographyClientBuilder httpLogOptions(HttpLogOptions logOptions)

设置在 HttpLogOptions 向/从服务发送和接收请求时要使用的 。

CryptographyClientBuilder jsonWebKey(JsonWebKey jsonWebKey)

JsonWebKey设置要用于本地加密操作的 。

CryptographyClientBuilder keyIdentifier(String keyId)

设置要用于加密操作的 JSON Web 密钥的 Azure 密钥保管库密钥标识符。

CryptographyClientBuilder pipeline(HttpPipeline pipeline)

HttpPipeline设置要用于服务客户端的 。

CryptographyClientBuilder retryOptions(RetryOptions retryOptions)

RetryOptions为通过客户端发出的所有请求设置 。

CryptographyClientBuilder retryPolicy(RetryPolicy retryPolicy)

RetryPolicy设置发送每个请求时使用的 。

CryptographyClientBuilder serviceVersion(CryptographyServiceVersion version)

设置发出 CryptographyServiceVersion API 请求时使用的 。

方法继承自 java.lang.Object

构造函数详细信息

CryptographyClientBuilder

public CryptographyClientBuilder()

具有默认值的构造函数。

方法详细信息

addPolicy

public CryptographyClientBuilder addPolicy(HttpPipelinePolicy policy)

添加 , HttpPipelinePolicy 以应用于发送的每个请求。

注意: 请务必了解 HttpTrait API 的优先顺序。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则将基于提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果指定 了 , HttpPipeline 则也会忽略这些 API,因此请务必参考实现此特征的类型的文档以了解完整的含义集。

Parameters:

policy - 一个 HttpPipelinePolicy

Returns:

已更新的 CryptographyClientBuilder 对象。

buildAsyncClient

public CryptographyAsyncClient buildAsyncClient()

CryptographyAsyncClient基于生成器中设置的选项创建 。 每次 buildAsyncClient() 调用 时,都会创建 的新 CryptographyAsyncClient 实例。

如果 jsonWebKey(JsonWebKey jsonWebKey) 设置了 ,则忽略所有其他生成器设置。

如果 pipeline(HttpPipeline pipeline) 设置了 ,则 pipeline 使用 和 keyIdentifier(String keyId)) 创建 CryptographyAsyncClient。 将忽略所有其他生成器设置。 如果未 pipeline 设置 ,则需要 credential(TokenCredential credential)keyIdentifier(String keyId) 来生成 CryptographyAsyncClient

Returns:

一个 CryptographyAsyncClient ,其中包含从生成器设置的选项。

buildClient

public CryptographyClient buildClient()

CryptographyClient基于生成器中设置的选项创建 。 每次 buildClient() 调用 时,都会创建 的新 CryptographyClient 实例。

如果 jsonWebKey(JsonWebKey jsonWebKey) 设置了 ,则忽略所有其他生成器设置。

如果 pipeline(HttpPipeline pipeline) 设置了 ,则 pipeline 使用 和 keyIdentifier(String keyId) 创建 CryptographyClient。 将忽略所有其他生成器设置。 如果未 pipeline 设置 ,则需要 credential(TokenCredential credential)keyIdentifier(String keyId) 来生成 CryptographyClient

Returns:

一个 CryptographyClient ,其中包含从生成器设置的选项。

clientOptions

public CryptographyClientBuilder clientOptions(ClientOptions clientOptions)

允许设置常见属性,例如应用程序 ID、标头、代理配置等。请注意,建议使用类的 HttpClientOptions 实例调用此方法, (基类) 的 ClientOptions 子类。 HttpClientOptions 子类提供更多适用于 HTTP 客户端的配置选项,这适用于实现此 HttpTrait 接口的任何类。

注意: 请务必了解 HttpTrait API 的优先顺序。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则将基于提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果指定 了 , HttpPipeline 则也会忽略这些 API,因此请务必参考实现此特征的类型的文档以了解完整的含义集。

Parameters:

clientOptions - 的已配置实例 HttpClientOptions

Returns:

已更新的 CryptographyClientBuilder 对象。

configuration

public CryptographyClientBuilder configuration(Configuration configuration)

设置在构造服务客户端期间使用的配置存储。 默认配置存储区是 的 global configuration store克隆,用于 NONE 在构造过程中绕过使用配置设置。

Parameters:

configuration - 用于获取配置详细信息的配置存储。

Returns:

已更新的 CryptographyClientBuilder 对象。

credential

public CryptographyClientBuilder credential(TokenCredential credential)

TokenCredential设置用于授权发送到服务的请求的 。 有关正确使用 TokenCredential 类型的更多详细信息,请参阅 Azure SDK for Java 标识和身份验证文档。

Parameters:

credential - TokenCredential 用于授权发送到服务的请求。

Returns:

已更新的 CryptographyClientBuilder 对象。

disableChallengeResourceVerification

public CryptographyClientBuilder disableChallengeResourceVerification()

禁用验证身份验证质询资源是否与密钥保管库或托管 HSM 域匹配。 默认情况下会执行此验证。

Returns:

已更新的 CryptographyClientBuilder 对象。

httpClient

public CryptographyClientBuilder httpClient(HttpClient client)

HttpClient设置用于向/从服务发送和接收请求的 。

注意: 请务必了解 HttpTrait API 的优先顺序。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则将基于提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果指定 了 , HttpPipeline 则也会忽略这些 API,因此请务必参考实现此特征的类型的文档以了解完整的含义集。

Parameters:

client - 要 HttpClient 用于请求的 。

Returns:

已更新的 CryptographyClientBuilder 对象。

httpLogOptions

public CryptographyClientBuilder httpLogOptions(HttpLogOptions logOptions)

设置在 HttpLogOptions 向/从服务发送和接收请求时要使用的 。 logLevel如果未提供 ,则设置 的默认值HttpLogDetailLevel#NONE

注意: 请务必了解 HttpTrait API 的优先顺序。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则将基于提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果指定 了 , HttpPipeline 则也会忽略这些 API,因此请务必参考实现此特征的类型的文档以了解完整的含义集。

Parameters:

logOptions - 在 HttpLogOptions 向/从服务发送和接收请求时要使用的 。

Returns:

已更新的 CryptographyClientBuilder 对象。

jsonWebKey

public CryptographyClientBuilder jsonWebKey(JsonWebKey jsonWebKey)

JsonWebKey设置要用于本地加密操作的 。

如果 jsonWebKey 提供 ,则忽略所有其他生成器设置。

Parameters:

jsonWebKey - 用于本地加密操作的 JSON Web 密钥。

Returns:

已更新的 CryptographyClientBuilder 对象。

keyIdentifier

public CryptographyClientBuilder keyIdentifier(String keyId)

设置要用于加密操作的 JSON Web 密钥的 Azure 密钥保管库密钥标识符。 应验证此 URL 引用有效的 密钥保管库 或托管 HSM 资源。 有关详细信息,请参阅以下 文档

若要确保在执行 、 和 VerifyUnwrapDecrypt操作时的行为正确,建议分别对用于相应逆运算的特定密钥版本使用 CryptographyAsyncClientCryptographyClient 创建的 。 EncryptWrapSign

Parameters:

keyId - Azure 密钥保管库密钥保管库中存储的 JSON Web 密钥的密钥标识符。

Returns:

已更新的 CryptographyClientBuilder 对象。

pipeline

public CryptographyClientBuilder pipeline(HttpPipeline pipeline)

HttpPipeline设置要用于服务客户端的 。

注意: 请务必了解 HttpTrait API 的优先顺序。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则将基于提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果指定 了 , HttpPipeline 则也会忽略这些 API,因此请务必参考实现此特征的类型的文档以了解完整的含义集。

keyIdentifier(String keyId)设置 时pipeline不会忽略 。

Parameters:

pipeline - HttpPipeline 用于发送服务请求和接收响应。

Returns:

已更新的 CryptographyClientBuilder 对象。

retryOptions

public CryptographyClientBuilder retryOptions(RetryOptions retryOptions)

RetryOptions为通过客户端发出的所有请求设置 。

注意: 请务必了解 HttpTrait API 的优先顺序。 具体而言,如果 HttpPipeline 指定了 ,则这优先于特征中的所有其他 API,它们将被忽略。 HttpPipeline如果未指定,则将基于提供给此特征的设置在内部构造 HTTP 管道。 此外,实现此特征的类型中可能存在其他 API,如果指定 了 , HttpPipeline 则也会忽略这些 API,因此请务必参考实现此特征的类型的文档以了解完整的含义集。

设置此项与使用 是互斥的 retryPolicy(RetryPolicy retryPolicy)

Parameters:

retryOptions - 要 RetryOptions 用于通过客户端发出的所有请求的 。

Returns:

已更新的 CryptographyClientBuilder 对象。

retryPolicy

public CryptographyClientBuilder retryPolicy(RetryPolicy retryPolicy)

RetryPolicy设置发送每个请求时使用的 。 如果未提供,将在管道中使用默认重试策略。 设置此项与使用 是互斥的 retryOptions(RetryOptions retryOptions)

Parameters:

retryPolicy - RetryPolicy用户应用于每个请求的 。

Returns:

已更新的 CryptographyClientBuilder 对象。

serviceVersion

public CryptographyClientBuilder serviceVersion(CryptographyServiceVersion version)

设置发出 CryptographyServiceVersion API 请求时使用的 。

如果未提供服务版本,将使用的服务版本将是基于正在使用的客户端库版本的最新已知服务版本。 如果未指定服务版本,更新到客户端库的较新版本可能会移动到较新的服务版本。

Parameters:

version - CryptographyServiceVersion 发出请求时要使用的服务的 。

Returns:

已更新的 CryptographyClientBuilder 对象。

适用于