mcpField
A
azure-keyvault-keys-rust

azure-keyvault-keys-rust

github.com/sickn33Security48.7k61 installsUpdated today
Repository

About azure-keyvault-keys-rust

Azure Key Vault Keys SDK for Rust is a client library for accessing keys in Azure Key Vault. It is for Rust developers managing keys or performing cryptographic operations, and supports RSA, elliptic-curve, and HSM keys without exposing private keys during operations.

Key features

  1. 01Get, create, and list keys
  2. 02Delete keys
  3. 03Back up and restore keys
  4. 04RSA, EC, and HSM key support
  5. 05Perform cryptographic operations with keys

Use cases

  1. 01Read key metadata in a Rust application
  2. 02Create or manage Key Vault keys
  3. 03Back up and restore keys
  4. 04Sign or encrypt without exporting private keys

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/sickn33/agentic-awesome-skills --skill azure-keyvault-keys-rust

After installing, type/azure-keyvault-keys-rustin Claude Code to confirm it loaded.

Details

From the project README

Azure Key Vault Keys SDK for Rust

Client library for Azure Key Vault Keys — secure storage and management of cryptographic keys.

The examples below require a reviewed compatible crate set and replacement of every resource placeholder. Do not use production data for demonstration writes.

Installation

cargo add azure_security_keyvault_keys@=1.0.1 azure_identity@=1.0.0 azure_core@=1.1.0

Environment Variables

export AZURE_KEYVAULT_URL="https://<vault-name>.vault.azure.net/"

Authentication

use azure_identity::DeveloperToolsCredential;
use azure_security_keyvault_keys::KeyClient;

let credential = DeveloperToolsCredential::new(None)?;
let client = KeyClient::new(
    "https://<vault-name>.vault.azure.net/",
    credential.clone(),
    None,
)?;

Key Types

TypeDescription
RSARSA keys (2048, 3072, 4096 bits)
ECElliptic curve keys (P-256, P-384, P-521)
RSA-HSMHSM-protected RSA keys
EC-HSMHSM-protected EC keys

Core Operations

Get Key
let key = client
    .get_key("key-name", None)
    .await?
    .into_model()?;

println!("Key ID: {:?}", key.key.as_ref().map(|k| &k.kid));
Create Key
use azure_security_keyvault_keys::models::{CreateKeyParameters, KeyType};

let params = CreateKeyParameters {
    kty: Some(KeyType::Rsa),
    key_size: Some(2048),
    ..Default::default()
};

let key = client
    .create_key("key-name", params.try_into()?, None)
    .await?
    .into_model()?;
Create EC Key
use azure_security_keyvault_keys::models::{CreateKeyParameters, KeyType, CurveName};

let params = CreateKeyParameters {
    kty: Some(KeyType::Ec),
    curve: Some(CurveName::P256),
    ..Default::default()
};

let key = client
    .create_key("ec-key", params.try_into()?, None)
    .await?
    .into_model()?;
Delete Key
client.delete_key("key-name", None).await?;
List Keys
use azure_security_keyvault_keys::ResourceExt;
use futures::TryStreamExt;

let mut pager = client.list_key_properties(None)?;
while let Some(key) = pager.try_next().await? {
    let name = key.resource_id()?.name;
    println!("Key: {}", name);
}
Backup Key
let backup = client.backup_key("key-name", None).await?.into_model()?;
// Store the returned encrypted backup securely; do not print it.
Restore Key
use azure_security_keyvault_keys::models::RestoreKeyParameters;

let params = RestoreKeyParameters {
    key_bundle_backup: backup_bytes,
};

client.restore_key(params.try_into()?, None).await?;

Cryptographic Operations

Key Vault can perform crypto operations without exposing the private key:

// For cryptographic operations, use the key's operations
// Available operations depend on key type and permissions:
// - encrypt/decrypt (RSA)
// - sign/verify (RSA, EC)
// - wrapKey/unwrapKey (RSA)

Best Practices

  1. Use Entra ID auth — DeveloperToolsCredential for dev, ManagedIdentityCredential for production
  2. Use HSM keys for sensitive workloads — hardware-protected keys
  3. Use EC for signing — more efficient than RSA
  4. Use envelope encryption — RSA can wrap a symmetric data key; do not encrypt arbitrary bulk data directly with RSA
  5. Backup keys — for disaster recovery
  6. Enable soft delete — required for production vaults
  7. Use key rotation — create new versions periodically

RBAC Permissions

Assign these Key Vault roles:

  • Key Vault Crypto User — use keys for crypto operations
  • Key Vault Crypto Officer — full CRUD on keys

The reviewed example set uses azure_security_keyvault_keys 1.0.1 and compatible Azure core/credential crates. Record and commit Cargo.lock; source/API review is not a compiler or live-service test.

Reference Links

ResourceLink
API Referencehttps://docs.rs/azure_security_keyvault_keys
Source Codehttps://github.com/Azure/azure-sdk-for-rust/tree/main/sdk/keyvault/azure_security_keyvault_keys
crates.iohttps://crates.io/crates/azure_security_keyvault_keys

When to Use

Use when a Rust application retrieves public key metadata or performs authorized Key Vault key creation, versioning, backup, restoration or cryptographic operations.

Limitations

  • Examples are fragments inside async application code, with compatible pinned Azure crates and the required Tokio/Serde/Futures dependencies; verify the selected version’s API before use. They were reviewed against official source/reference, not compiled or run against a cloud account here.
  • Use an authorized tenant, resource and identity with least privilege. Writes, overwrites, deletes, backup retrieval and account changes require the corresponding scope; cleanup may remove only explicitly identified disposable resources. Bound requests, retries and downloaded bytes, and do not log payloads, credentials or secret values.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

Comments

Markdown supported