KeyVaultLibrary.Platform 1.0.8.2-beta

This is a prerelease version of KeyVaultLibrary.Platform.
There is a newer version of this package available.
See the version list below for details.
dotnet add package KeyVaultLibrary.Platform --version 1.0.8.2-beta
                    
NuGet\Install-Package KeyVaultLibrary.Platform -Version 1.0.8.2-beta
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KeyVaultLibrary.Platform" Version="1.0.8.2-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KeyVaultLibrary.Platform" Version="1.0.8.2-beta" />
                    
Directory.Packages.props
<PackageReference Include="KeyVaultLibrary.Platform" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KeyVaultLibrary.Platform --version 1.0.8.2-beta
                    
#r "nuget: KeyVaultLibrary.Platform, 1.0.8.2-beta"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KeyVaultLibrary.Platform@1.0.8.2-beta
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KeyVaultLibrary.Platform&version=1.0.8.2-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=KeyVaultLibrary.Platform&version=1.0.8.2-beta&prerelease
                    
Install as a Cake Tool

KeyVaultLibrary.Platform

A robust Azure Key Vault integration library providing enhanced security, performance, and reliability features for accessing and managing secrets in multi-tenant environments.

Overview

KeyVaultLibrary simplifies Azure Key Vault integration with advanced features including:

  • Memory-based caching with configurable expiration for improved performance
  • Tenant-aware secret management for multi-tenant applications
  • Comprehensive retry policies for handling transient failures
  • Secure connection string management with encryption/decryption
  • Extensive error handling and detailed logging
  • Seamless dependency injection integration

Multi-Framework Support

This library supports the following .NET frameworks:

  • .NET Framework 4.7.2
  • .NET 6.0
  • .NET 8.0

Installation

Install the package from NuGet:

dotnet add package KeyVaultLibrary.Platform

Or via Package Manager Console:

Install-Package KeyVaultLibrary.Platform

Configuration

Add the following to your appsettings.json:

{
  "KeyVaultUri": "https://your-keyvault.vault.azure.net/",
  "LicenseKey": "your-license-key"
}

Usage

Dependency Injection Setup

// Register with dependency injection using URL
services.AddKeyVaultService("https://your-keyvault.vault.azure.net/");

// Register with user-assigned managed identity
services.AddKeyVaultServiceWithUserAssignedManagedIdentity(
    "https://your-keyvault.vault.azure.net/",
    "your-managed-identity-client-id");

// Register with configuration
services.AddKeyVaultService(configuration);

// Register with configuration for user-assigned managed identity
services.AddKeyVaultServiceWithUserAssignedManagedIdentity(
    configuration,
    keyVaultUrlKey: "KeyVault:Url",
    managedIdentityClientIdKey: "KeyVault:ManagedIdentityClientId");

// Register with custom options
services.AddKeyVaultService(options => {
    options.KeyVaultUrl = "https://your-keyvault.vault.azure.net/";
    options.CacheExpirationMinutes = 60;
    options.EnableAutoRefresh = true;
    options.EnableCacheInvalidation = true;
});

// Register with custom options using user-assigned managed identity
services.AddKeyVaultService(options => {
    options.KeyVaultUrl = "https://your-keyvault.vault.azure.net/";
    options.ManagedIdentityClientId = "your-managed-identity-client-id";
    options.CacheExpirationMinutes = 60;
    options.EnableAutoRefresh = true;
});

Direct Instantiation

// Using KeyVaultFactory (recommended)
IKeyVaultService keyVaultService = KeyVaultFactory.Create(keyVaultUrl);

// With user-assigned managed identity
IKeyVaultService keyVaultService = KeyVaultFactory.CreateWithUserAssignedManagedIdentity(keyVaultUrl, "your-managed-identity-client-id");

// With custom token credential
var credential = new DefaultAzureCredential();
IKeyVaultService keyVaultService = KeyVaultFactory.Create(keyVaultUrl, credential);

// With custom options
var options = new KeyVaultServiceOptions {
    KeyVaultUrl = keyVaultUrl,
    CacheExpirationMinutes = 60
};
IKeyVaultService keyVaultService = KeyVaultFactory.Create(options);

// With custom options and user-assigned managed identity
var options = new KeyVaultServiceOptions {
    KeyVaultUrl = keyVaultUrl,
    ManagedIdentityClientId = "your-managed-identity-client-id",
    CacheExpirationMinutes = 60
};
IKeyVaultService keyVaultService = KeyVaultFactory.Create(options);

Retrieving Secrets

// Get connection string for a specific tenant
string connectionString = await keyVaultService.GetConnectionStringAsync(tenantKey, configuration);

// Get default connection string
string defaultConnection = await keyVaultService.GetConnectionStringAsync(configuration);

// Get settings secret value with tenant context
string settingValue = await keyVaultService.GetSettingsSecretValue(configuration, "SettingName", tenantKey);

// Get global settings secret value
string globalSetting = await keyVaultService.GetSettingsSecretValue(configuration, "GlobalSettingName");

Using with SQL Connections

// Get a SQL connection for a specific tenant
using (var connection = await keyVaultService.GetSqlConnectionAsync(configuration, tenantKey))
{
    // Use the connection
}

// Execute an action with automatic connection management and retry
await keyVaultService.ExecuteWithConnectionAsync(configuration, async (connection) => {
    // Use the connection to execute commands
    using (var command = connection.CreateCommand())
    {
        command.CommandText = "SELECT * FROM MyTable";
        using (var reader = await command.ExecuteReaderAsync())
        {
            // Process results
        }
    }
}, tenantKey);

Framework-Specific Considerations

  • When targeting .NET Framework 4.7.2, nullable reference types are not supported
  • For .NET 6.0 and .NET 8.0, nullable reference types are supported
  • The library automatically handles compatibility differences between frameworks

Features

Security

  • Secure access to Azure Key Vault secrets
  • Encryption/decryption of sensitive data using AES with RFC2898 key derivation
  • Support for various authentication methods (Managed Identity, Service Principal, Client Secret)
  • Tenant key decryption for enhanced security in multi-tenant environments

Performance

  • Memory-based caching with configurable expiration
  • Size-based cache management with automatic compaction
  • Optional auto-refresh of cached secrets
  • Cache invalidation on secret updates
  • Efficient cache key generation for tenant-specific secrets

Reliability

  • Intelligent retry policies for transient failures (HTTP 429, 5xx errors)
  • Comprehensive error handling with detailed logging
  • Fallback mechanisms when Key Vault is unavailable
  • Graceful degradation when services are unavailable

Multi-tenancy

  • Tenant-aware secret management
  • Tenant-specific connection strings
  • Tenant isolation for settings

Integration

  • Dependency injection support
  • Extension methods for common scenarios
  • SQL connection management helpers

Best Practices

  1. Use Caching: Enable caching to reduce the number of calls to Azure Key Vault
  2. Handle Exceptions: Always wrap Key Vault calls in try-catch blocks
  3. Provide Fallbacks: Implement fallback mechanisms for when Key Vault is unavailable
  4. Use Async Methods: Prefer async methods for better performance
  5. Secure Connection Strings: Store connection strings in Key Vault rather than in configuration files
  6. Consider Alternative Caching: For high-load scenarios, consider alternative caching mechanisms:
    • Redis Cache for distributed high-performance caching
    • Azure Cache for Redis as a managed service option
    • Memory Cache with periodic persistence for smaller workloads
    • Blob storage with local memory cache for less frequently accessed secrets

Troubleshooting

Common Issues

  1. Authentication Failures:

    • Ensure your application has the correct permissions to access the Key Vault
    • Verify that the Managed Identity or Service Principal is correctly configured
  2. Secret Not Found:

    • Check that the secret name is correct and exists in the Key Vault
    • Verify that the Key Vault URL is correct
  3. Connection Issues:

    • Check network connectivity to Azure Key Vault
    • Verify that any firewalls or network security groups allow traffic to Azure Key Vault
  4. Package Dependency Conflicts:

    • When encountering errors like NU1106: Unable to satisfy conflicting requests for 'System.Xml.XmlDocument', use package reference aliases in your project file:
    <PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    
    • Alternatively, add package binding redirects in your app.config or web.config:
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Xml.XmlDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>
    
    • For .NET Core and .NET 5+ projects, consider using <PackageReference> with PrivateAssets="All" to prevent dependency conflicts

Dependencies

The library uses different package versions based on the target framework to ensure maximum compatibility:

  • Azure.Identity (1.12.0)
  • Azure.Security.KeyVault.Secrets (4.6.0)
  • Microsoft.Extensions.Caching.Memory (8.0.0)
  • Microsoft.Extensions.Configuration (8.0.0)
  • Microsoft.Extensions.DependencyInjection (8.0.0)
  • Microsoft.Extensions.Logging (8.0.0)
  • Polly (8.2.0)
  • System.Data.SqlClient (4.9.0)
  • Newtonsoft.Json (for serialization/deserialization)
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on KeyVaultLibrary.Platform:

Package Downloads
UserSessionService.Platform

Server-side user session management with SQL and Redis store providers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 1,657 5/1/2026
2.0.0-beta 120 4/29/2026
1.0.8.9 3,634 9/16/2025
1.0.8.9-beta 316 9/15/2025
1.0.8.8 269 9/3/2025
1.0.8.7 472 8/21/2025
1.0.8.7-beta 212 8/18/2025
1.0.8.6 721 8/6/2025
1.0.8.6-beta 317 8/5/2025
1.0.8.4-beta 235 8/4/2025
1.0.8.3-beta 194 7/31/2025
1.0.8.2-beta 187 7/30/2025
1.0.8.1 184 7/29/2025
1.0.8 513 7/25/2025
1.0.8-beta 186 7/28/2025
1.0.7 731 7/22/2025
1.0.6 284 7/1/2025
1.0.5 507 7/1/2025