您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

用于 Java 的 Azure Key Vault 库Azure Key Vault libraries for Java

概述Overview

使用 Azure Key Vault 保护及管理云应用程序与服务使用的加密密钥和机密。Safeguard and manage cryptographic keys and secrets used by cloud applications and services with Azure Key Vault.

若要开始使用 Azure Key Vault,请参阅 Azure Key Vault 入门To get started with Azure Key Vault, see Get started with Azure Key Vault.

客户端库Client library

使用客户端库在 Azure Key Vault 中创建、更新和删除密钥与机密。Create, update, and delete keys and secrets in Azure Key Vault with the client libraries.

向 Maven pom.xml 文件中添加依赖项,以便在项目中使用客户端库。Add a dependency to your Maven pom.xml file to use the client library in your project.

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-keyvault</artifactId>
    <version>1.1.2</version>
</dependency>

示例Example

从 Key Vault 检索JSON Web 密钥Retrieve a JSON web key from a Key Vault.

KeyVaultClient kvc = new KeyVaultClient(credentials);
KeyBundle returnedKeyBundle = kvc.getKey(vaultUrl, keyName);
JsonWebKey jsonKey = returnedKeyBundle.key();

管理 APIManagement API

使用 Azure Key Vault 管理库来创建 Key Vault、授权应用程序及管理权限。Use the Azure Key Vault management libraries to create key vaults, authorize applications, and manage permissions.

向 Maven pom.xml 文件中添加依赖项,以便在项目中使用管理 API。Add a dependency to your Maven pom.xml file to use the management API in your project.

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-mgmt-keyvault</artifactId>
    <version>1.15.0</version>
</dependency>

示例Example

使用服务主体 clientId 授权运行的应用程序,以便从 Key Vault 中检索机密。Authorize and application running with service principal clientId to list and retrieve secrets from a key vault.

vault1 = vault1.update()
            .defineAccessPolicy()
                .forServicePrincipal(clientId)
                .allowKeyAllPermissions()
                .allowSecretPermissions(SecretPermissions.GET)
                .allowSecretPermissions(SecretPermissions.LIST)
                .attach()
            .apply();

示例Samples

详细了解可在应用中使用的 Azure Key Vault 示例 Java 代码Explore more sample Java code for Azure Key Vault you can use in your apps.