Azure Key Vault Keys SDK for .NET. Client library for managing cryptographic keys in Azure Key Vault and Managed HSM. Use for key creation, rotation, encryption, decryption, signing, and verification.
risk
unknown
source
community
date added
2026-02-27
Azure.Security.KeyVault.Keys (.NET)
Client library for managing cryptographic keys in Azure Key Vault and Managed HSM.
// Get specific key (latest version)KeyVaultKey key =await client.GetKeyAsync("my-rsa-key");Console.WriteLine($"Key ID: {key.Id}");Console.WriteLine($"Key Type: {key.KeyType}");Console.WriteLine($"Version: {key.Properties.Version}");// Get specific versionKeyVaultKey keyVersion =await client.GetKeyAsync("my-rsa-key","version-id");// List all keysawaitforeach(KeyProperties keyProps in client.GetPropertiesOfKeysAsync()){ Console.WriteLine($"Key: {keyProps.Name}, Enabled: {keyProps.Enabled}");}// List key versionsawaitforeach(KeyProperties version in client.GetPropertiesOfKeyVersionsAsync("my-rsa-key")){ Console.WriteLine($"Version: {version.Version}, Created: {version.CreatedOn}");}
// Data to signbyte[] data = Encoding.UTF8.GetBytes("Data to sign");// Sign data (computes hash internally)SignResult signResult =await cryptoClient.SignDataAsync( SignatureAlgorithm.RS256, data);// Verify signatureVerifyResult verifyResult =await cryptoClient.VerifyDataAsync( SignatureAlgorithm.RS256, data, signResult.Signature);Console.WriteLine($"Signature valid: {verifyResult.IsValid}");// Or sign pre-computed hashusingvar sha256 = SHA256.Create();byte[] hash = sha256.ComputeHash(data);SignResult signHashResult =await cryptoClient.SignAsync( SignatureAlgorithm.RS256, hash);
Key Resolver
usingAzure.Security.KeyVault.Keys.Cryptography;var resolver =newKeyResolver(newDefaultAzureCredential());// Resolve key by ID to get CryptographyClientCryptographyClient cryptoClient =await resolver.ResolveAsync(newUri("https://myvault.vault.azure.net/keys/my-key/version"));// Use for encryptionEncryptResult result =await cryptoClient.EncryptAsync( EncryptionAlgorithm.RsaOaep256, plaintext);
Key Rotation
// Rotate key (creates new version)KeyVaultKey rotatedKey =await client.RotateKeyAsync("my-rsa-key");Console.WriteLine($"New version: {rotatedKey.Properties.Version}");// Get rotation policyKeyRotationPolicy policy =await client.GetKeyRotationPolicyAsync("my-rsa-key");// Update rotation policypolicy.ExpiresIn ="P90D";// 90 dayspolicy.LifetimeActions.Add(newKeyRotationLifetimeAction{ Action = KeyRotationPolicyAction.Rotate, TimeBeforeExpiry ="P30D"// Rotate 30 days before expiry});await client.UpdateKeyRotationPolicyAsync("my-rsa-key", policy);
Key Types Reference
Type
Purpose
KeyClient
Key management operations
CryptographyClient
Cryptographic operations
KeyResolver
Resolve key ID to CryptographyClient
KeyVaultKey
Key with cryptographic material
KeyProperties
Key metadata (no crypto material)
CreateRsaKeyOptions
RSA key creation options
CreateEcKeyOptions
EC key creation options
CreateOctKeyOptions
Symmetric key options
EncryptResult
Encryption result
DecryptResult
Decryption result
SignResult
Signing result
VerifyResult
Verification result
WrapResult
Key wrap result
UnwrapResult
Key unwrap result
Algorithms Reference
Encryption Algorithms
Algorithm
Key Type
Description
RsaOaep
RSA
RSA-OAEP
RsaOaep256
RSA
RSA-OAEP-256
Rsa15
RSA
RSA 1.5 (legacy)
A128Gcm
Oct
AES-128-GCM
A256Gcm
Oct
AES-256-GCM
Signature Algorithms
Algorithm
Key Type
Description
RS256
RSA
RSASSA-PKCS1-v1_5 SHA-256
RS384
RSA
RSASSA-PKCS1-v1_5 SHA-384
RS512
RSA
RSASSA-PKCS1-v1_5 SHA-512
PS256
RSA
RSASSA-PSS SHA-256
ES256
EC
ECDSA P-256 SHA-256
ES384
EC
ECDSA P-384 SHA-384
ES512
EC
ECDSA P-521 SHA-512
Key Wrap Algorithms
Algorithm
Key Type
Description
RsaOaep
RSA
RSA-OAEP
RsaOaep256
RSA
RSA-OAEP-256
A128KW
Oct
AES-128 Key Wrap
A256KW
Oct
AES-256 Key Wrap
Best Practices
Use Managed Identity — Prefer DefaultAzureCredential over secrets
Enable soft-delete — Protect against accidental deletion
Use HSM-backed keys — Set HardwareProtected = true for sensitive keys
Implement key rotation — Use automatic rotation policies
Limit key operations — Only enable required KeyOperations
Set expiration dates — Always set ExpiresOn for keys
Use specific versions — Pin to versions in production
Cache CryptographyClient — Reuse for multiple operations