ByteDev.Azure.KeyVault 2.3.0

.NET Standard 2.1
dotnet add package ByteDev.Azure.KeyVault --version 2.3.0
NuGet\Install-Package ByteDev.Azure.KeyVault -Version 2.3.0
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="ByteDev.Azure.KeyVault" Version="2.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ByteDev.Azure.KeyVault --version 2.3.0
#r "nuget: ByteDev.Azure.KeyVault, 2.3.0"
#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.
// Install ByteDev.Azure.KeyVault as a Cake Addin
#addin nuget:?package=ByteDev.Azure.KeyVault&version=2.3.0

// Install ByteDev.Azure.KeyVault as a Cake Tool
#tool nuget:?package=ByteDev.Azure.KeyVault&version=2.3.0

ByteDev.Azure.KeyVault

.NET Standard library that provides some extended Azure Key Vault functionality build on top of the official Azure packages.

Installation

ByteDev.Azure.KeyVault has been written as a .NET Standard 2.1 library.

ByteDev.Azure.KeyVault is hosted as a package on nuget.org. To install from the Package Manager Console in Visual Studio run:

Install-Package ByteDev.Azure.KeyVault

Further details can be found on the nuget page.

Release Notes

Releases follow semantic versioning.

Full details of the release notes can be viewed on GitHub.

Usage

Secrets

Secrets functionality is accessed through the KeyVaultSecretClient class.

Methods:

  • DeleteAllAsync
  • DeleteAndPurgeAsync
  • DeleteAsync
  • DeleteIfExistsAsync
  • ExistsAsync
  • GetAllAsync
  • GetAsync
  • GetDeletedAsync
  • GetDeletedIfExistsAsync
  • GetIfExistsAsync
  • GetSectionAsync
  • GetValueAsync
  • GetValueIfExistsAsync
  • GetValuesIfExistsAsync
  • IsDeletedAsync
  • PurgeAllDeletedAsync
  • PurgeAsync
  • PurgeIfDeletedAsync
  • SafeSetValueAsync
  • SetValueAsync

Example usage:

using ByteDev.Azure.KeyVault.Secrets;

// ...

IKeyVaultSecretClient client = new KeyVaultSecretClient(keyVaultUri);

// Create a secret
await client.SetValueAsync("Test1", "Some value");

// Get the secret's value
string value = await client.GetValueAsync("Test1");

// Delete the secret
await client.DeleteAsync("Test1", true);

// Purge the soft deleted secret
await client.PurgeAsync("Test1");

Secrets.Serialization

Deserialize Azure Key Vault secrets directly to a new class instance.

// Entitiy class (class you want to deserialize to)

public class Person
{
    public string Name { get; set; }

    [KeyVaultSecretName("email")]
    public string EmailAddress { get; set; }

    [KeyVaultSecretIgnore]
    public string Mobile { get; set; }
}

The class above will check Azure Key Vault for the following named secrets:

  • Name
  • email

The Mobile property will not be set on deserialization as it has been decorated with a KeyVaultSecretIgnoreAttribute.

using ByteDev.Azure.KeyVault.Secrets;
using ByteDev.Azure.KeyVault.Secrets.Serialization;

// ...

IKeyVaultSecretClient client = new KeyVaultSecretClient(keyVaultUri);

IKeyVaultSecretSerializer serializer = new KeyVaultSecretSerializer(client);

var person = await serializer.DeserializeAsync<Person>();

// person.Name == (Value of "Name" secret)
// person.EmailAddress == (Value of "email" secret)
// person.Mobile == null

Keys

Keys functionality is accessed through the KeyVaultKeyClient class.

Methods:

  • CreateAsync
  • DeleteAsync
  • DeleteIfExistsAsync
  • EncryptAsync / DecryptAsync
  • ExistsAsync
  • GetAsync
  • PurgeAsync
  • PurgeIfDeletedAsync
  • SignAsync / VerifyAsync
  • WrapAsync / UnwrapAsync

Example usage:

using ByteDev.Azure.KeyVault.Keys;

// ...

IKeyVaultKeyClient client = new KeyVaultKeyClient(keyVaultUri);

const string keyName = "MyKey";
const string clearText = "test string";

// Encrypt/decrypt some text using the Key Vault key

byte[] cipher = await client.EncryptAsync(keyName, EncryptionAlgorithm.RsaOaep, clearText, Encoding.Unicode);

string result = await client.DecryptAsync(keyName, EncryptionAlgorithm.RsaOaep, cipher, Encoding.Unicode);

// result == "test string"
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.1
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ByteDev.Azure.KeyVault:

Package Downloads
ByteDev.Testing

.NET Standard library that provides some testing related functionality.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.0 824 7/6/2022
2.2.0 286 7/5/2022
2.1.0 468 6/28/2022
2.0.0 320 3/29/2022
1.2.0 298 3/28/2022
1.1.0 241 3/31/2021
1.0.0 306 9/7/2020