![]() |
VOOZH | about |
dotnet add package Azure.Security.KeyVault.Certificates --version 4.9.0
NuGet\Install-Package Azure.Security.KeyVault.Certificates -Version 4.9.0
<PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.9.0" />
<PackageVersion Include="Azure.Security.KeyVault.Certificates" Version="4.9.0" />Directory.Packages.props
<PackageReference Include="Azure.Security.KeyVault.Certificates" />Project file
paket add Azure.Security.KeyVault.Certificates --version 4.9.0
#r "nuget: Azure.Security.KeyVault.Certificates, 4.9.0"
#:package Azure.Security.KeyVault.Certificates@4.9.0
#addin nuget:?package=Azure.Security.KeyVault.Certificates&version=4.9.0Install as a Cake Addin
#tool nuget:?package=Azure.Security.KeyVault.Certificates&version=4.9.0Install as a Cake Tool
Azure Key Vault is a cloud service that provides secure storage and automated management of certificates used throughout a cloud application. Multiple certificates, and multiple versions of the same certificate, can be kept in the Azure Key Vault. Each certificate in the vault has a policy associated with it which controls the issuance and lifetime of the certificate, along with actions to be taken as certificates near expiry.
The Azure Key Vault certificates client library enables programmatically managing certificates, offering methods to create, update, list, and delete certificates, policies, issuers, and contacts. The library also supports managing pending certificate operations and management of deleted certificates.
Source code | Package (NuGet) | API reference documentation | Product documentation | Samples | Migration guide
Install the Azure Key Vault certificates client library for .NET with NuGet:
dotnet add package Azure.Security.KeyVault.Certificates
If you use the Azure CLI, replace <your-resource-group-name> and <your-key-vault-name> with your own, unique names:
az keyvault create --resource-group <your-resource-group-name> --name <your-key-vault-name>
In order to interact with the Azure Key Vault service, you'll need to create an instance of the CertificateClient class. You need a vault url, which you may see as "DNS Name" in the portal, and credentials to instantiate a client object.
The examples shown below use a DefaultAzureCredential, which is appropriate for most scenarios including local development and production environments.
Additionally, we recommend using a managed identity for authentication in production environments.
You can find more information on different ways of authenticating and their corresponding credential types in the Azure Identity documentation.
To use the DefaultAzureCredential provider shown below,
or other credential providers provided with the Azure SDK, you must first install the Azure.Identity package:
dotnet add package Azure.Identity
Instantiate a DefaultAzureCredential to pass to the client.
The same instance of a token credential can be used with multiple clients if they will be authenticating with the same identity.
// Create a new certificate client using the default credential from Azure.Identity using environment variables previously set,
// including AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID.
var client = new CertificateClient(vaultUri: new Uri(vaultUrl), credential: new DefaultAzureCredential());
A KeyVaultCertificate is the fundamental resource within Azure Key Vault. You'll use certificates to encrypt and verify encrypted or signed data.
With a CertificateClient you can get certificates from the vault, create new certificates and
new versions of existing certificates, update certificate metadata, and delete certificates. You
can also manage certificate issuers, contacts, and management policies of certificates. This is
illustrated in the examples below.
We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.
Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime
The Azure.Security.KeyVault.Certificates package supports synchronous and asynchronous APIs.
The following section provides several code snippets using the clientcreated above, covering some of the most common Azure Key Vault certificate service related tasks:
StartCreateCertificate creates a certificate to be stored in the Azure Key Vault. If a certificate with
the same name already exists, then a new version of the certificate is created.
When creating the certificate the user can specify the policy which controls the certificate lifetime. If no policy is specified the default policy will be used. The StartCreateCertificate operation returns a CertificateOperation. The following example creates a self-signed certificate with the default policy.
// Create a certificate. This starts a long running operation to create and sign the certificate.
CertificateOperation operation = client.StartCreateCertificate("MyCertificate", CertificatePolicy.Default);
// You can await the completion of the create certificate operation.
// You should run UpdateStatus in another thread or do other work like pumping messages between calls.
while (!operation.HasCompleted)
{
Thread.Sleep(2000);
operation.UpdateStatus();
}
KeyVaultCertificateWithPolicy certificate = operation.Value;
NOTE: Depending on the certificate issuer and validation methods, certificate creation and signing can take an indeterminate amount of time. Users should only wait on certificate operations when the operation can be reasonably completed in the scope of the application, such as with self-signed certificates or issuers with well known response times.
GetCertificate retrieves the latest version of a certificate stored in the Azure Key Vault along with its CertificatePolicy.
KeyVaultCertificateWithPolicy certificateWithPolicy = client.GetCertificate("MyCertificate");
GetCertificateVersion retrieves a specific version of a certificate in the vault.
KeyVaultCertificate certificate = client.GetCertificateVersion(certificateWithPolicy.Name, certificateWithPolicy.Properties.Version);
UpdateCertificate updates a certificate stored in the Azure Key Vault.
CertificateProperties certificateProperties = new CertificateProperties(certificate.Id);
certificateProperties.Tags["key1"] = "value1";
KeyVaultCertificate updated = client.UpdateCertificateProperties(certificateProperties);
GetCertificates enumerates the certificates in the vault, returning select properties of the
certificate. Sensitive fields of the certificate will not be returned. This operation
requires the certificates/list permission.
Pageable<CertificateProperties> allCertificates = client.GetPropertiesOfCertificates();
foreach (CertificateProperties certificateProperties in allCertificates)
{
Console.WriteLine(certificateProperties.Name);
}
DeleteCertificate deletes all versions of a certificate stored in the Azure Key Vault. When soft-delete
is not enabled for the Azure Key Vault, this operation permanently deletes the certificate. If soft delete is enabled the certificate is marked for deletion and can be optionally purged or recovered up until its scheduled purge date.
DeleteCertificateOperation operation = client.StartDeleteCertificate("MyCertificate");
// You only need to wait for completion if you want to purge or recover the certificate.
// You should call `UpdateStatus` in another thread or after doing additional work like pumping messages.
while (!operation.HasCompleted)
{
Thread.Sleep(2000);
operation.UpdateStatus();
}
DeletedCertificate certificate = operation.Value;
client.PurgeDeletedCertificate(certificate.Name);
The asynchronous APIs are identical to their synchronous counterparts, but return with the typical "Async" suffix for asynchronous methods and return a Task.
This example creates a certificate in the Azure Key Vault with the specified optional arguments.
// Create a certificate. This starts a long running operation to create and sign the certificate.
CertificateOperation operation = await client.StartCreateCertificateAsync("MyCertificate", CertificatePolicy.Default);
// You can await the completion of the create certificate operation.
KeyVaultCertificateWithPolicy certificate = await operation.WaitForCompletionAsync();
Listing certificate does not rely on awaiting the GetPropertiesOfCertificatesAsync method, but returns an AsyncPageable<CertificateProperties> that you can use with the await foreach statement:
AsyncPageable<CertificateProperties> allCertificates = client.GetPropertiesOfCertificatesAsync();
await foreach (CertificateProperties certificateProperties in allCertificates)
{
Console.WriteLine(certificateProperties.Name);
}
When deleting a certificate asynchronously before you purge it, you can await the WaitForCompletionAsync method on the operation.
By default, this loops indefinitely but you can cancel it by passing a CancellationToken.
DeleteCertificateOperation operation = await client.StartDeleteCertificateAsync("MyCertificate");
// You only need to wait for completion if you want to purge or recover the certificate.
await operation.WaitForCompletionAsync();
DeletedCertificate certificate = operation.Value;
await client.PurgeDeletedCertificateAsync(certificate.Name);
See our troubleshooting guide for details on how to diagnose various failure scenarios.
When you interact with the Azure Key Vault certificates client library using the .NET SDK, errors returned by the service correspond to the same HTTP status codes returned for REST API requests.
For example, if you try to retrieve a Key that doesn't exist in your Azure Key Vault, a 404 error is returned, indicating Not Found.
try
{
KeyVaultCertificateWithPolicy certificateWithPolicy = client.GetCertificate("SomeCertificate");
}
catch (RequestFailedException ex)
{
Console.WriteLine(ex.ToString());
}
You will notice that additional information is logged, like the Client Request ID of the operation.
Message:
Azure.RequestFailedException : Service request failed.
Status: 404 (Not Found)
Content:
{"error":{"code":"CertificateNotFound","message":"Certificate not found: MyCertificate"}}
Headers:
Cache-Control: no-cache
Pragma: no-cache
Server: Microsoft-IIS/10.0
x-ms-keyvault-region: westus
x-ms-request-id: 625f870e-10ea-41e5-8380-282e5cf768f2
x-ms-keyvault-service-version: 1.1.0.866
x-ms-keyvault-network-info: addr=131.107.174.199;act_addr_fam=InterNetwork;
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Strict-Transport-Security: max-age=31536000;includeSubDomains
X-Content-Type-Options: nosniff
Date: Tue, 18 Jun 2019 16:02:11 GMT
Content-Length: 75
Content-Type: application/json; charset=utf-8
Expires: -1
Several Azure Key Vault certificates client library samples are available to you in this GitHub repository. These samples provide example code for additional scenarios commonly encountered while working with Azure Key Vault:
Sample1_HelloWorld.md - for working with Azure Key Vault certificates, including:
Sample2_GetCertificates.md - Example code for working with Azure Key Vault certificates, including:
See the CONTRIBUTING.md for details on building, testing, and contributing to these libraries.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact with any additional questions or comments.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Azure.Security.KeyVault.Certificates:
| Package | Downloads |
|---|---|
|
Microsoft.Identity.Web.Certificate
This package brings certificate management for MSAL.NET. |
|
|
Nuke.Common
The AKEless Build System for C#/.NET Signed by signpath.io from repository 'https://github.com/nuke-build/nuke' commit '8aaec258a7e00e5d98e013be025db1a42bc58d79' (see contained AppVeyorSettings.json file for build settings). |
|
|
AspNetCore.HealthChecks.AzureKeyVault
HealthChecks.AzureKeyVault is the health check package for Azure Key Vault secrets |
|
|
Aspire.Azure.Security.KeyVault
A client for Azure Key Vault that integrates with Aspire, including health checks, logging and telemetry. |
|
|
Service.Extensions.KeyVault
Extensions to provide consistent configurations and patterns for your service. |
Showing the top 20 popular GitHub repositories that depend on Azure.Security.KeyVault.Certificates:
| Repository | Stars |
|---|---|
|
microsoft/aspire
Aspire is the tool for code-first, extensible, observable dev and deploy.
|
|
|
win-acme/win-acme
Automate SSL/TLS certificates on Windows with ease
|
|
|
Azure/azure-powershell
Microsoft Azure PowerShell
|
|
|
Xabaril/AspNetCore.Diagnostics.HealthChecks
Enterprise HealthChecks for ASP.NET Core Diagnostics Package
|
|
|
testcontainers/testcontainers-dotnet
A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
|
|
|
nuke-build/nuke
🏗 The AKEless Build System for C#/.NET
|
|
|
skoruba/IdentityServer4.Admin
The administration for the IdentityServer4 and Asp.Net Core Identity
|
|
|
microsoft/mcp
Catalog of official Microsoft MCP (Model Context Protocol) server implementations for AI-powered data access and tool integration
|
|
|
enkodellc/blazorboilerplate
Blazor Boilerplate / Starter Template with MudBlazor
|
|
|
natemcmaster/LettuceEncrypt
Free, automatic HTTPS certificate generation for ASP.NET Core web apps
|
|
|
AzureAD/microsoft-authentication-library-for-dotnet
Microsoft Authentication Library (MSAL) for .NET
|
|
|
Azure/azure-mcp
The Azure MCP Server, bringing the power of Azure to your agents.
|
|
|
polymind-inc/acmebot
Automated ACME SSL/TLS certificate management built around Azure Key Vault
|
|
|
azure-ad-b2c/samples
Azure AD B2C custom policy solutions and samples.
|
|
|
AzureAD/microsoft-identity-web
Helps creating protected web apps and web APIs with Microsoft identity platform and Azure AD B2C
|
|
|
skoruba/Duende.IdentityServer.Admin
Modern admin UI for Duende IdentityServer and ASP.NET Core Identity 🚀
|
|
|
dotnet/sign
Code Signing CLI tool supporting Authenticode, NuGet, VSIX, and ClickOnce
|
|
|
simple-acme/simple-acme
A simple cross platform ACME client (for use with Let's Encrypt et al.)
|
|
|
thomhurst/ModularPipelines
Write your pipelines in C# !
|
|
|
vcsjones/AzureSignTool
SignTool Library and Azure Key Vault Support
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.10.0-beta.2 | 121 | 6/11/2026 |
| 4.10.0-beta.1 | 104 | 6/4/2026 |
| 4.9.0 | 166,546 | 5/27/2026 |
| 4.9.0-beta.1 | 1,512 | 4/7/2026 |
| 4.8.0 | 8,652,345 | 6/17/2025 |
| 4.8.0-beta.1 | 14,107 | 4/9/2025 |
| 4.7.0 | 13,086,913 | 10/15/2024 |
| 4.6.0 | 92,835,029 | 2/15/2024 |
| 4.6.0-beta.2 | 9,828 | 11/13/2023 |
| 4.6.0-beta.1 | 406 | 11/10/2023 |
| 4.5.1 | 35,694,943 | 3/31/2023 |
| 4.5.0 | 789,556 | 3/14/2023 |
| 4.5.0-beta.1 | 16,677 | 11/9/2022 |
| 4.4.0 | 4,100,359 | 9/20/2022 |
| 4.3.0 | 4,956,534 | 3/26/2022 |
| 4.3.0-beta.4 | 19,042 | 1/13/2022 |
| 4.3.0-beta.2 | 13,440 | 10/14/2021 |
| 4.3.0-beta.1 | 179,182 | 8/11/2021 |
| 4.2.0 | 5,001,500 | 6/16/2021 |