Azure Key Vault API Guide

Use Azure Key Vault with Chilkat to manage secrets, keys and certificates, perform cryptographic operations, and sign documents with a remote private key. This guide connects 46 examples using Chilkat.Http, certificate and signing helpers, and the Chilkat.Secrets convenience API.

Choose the resource and integration

Start with the operation your application needs
TaskResource or APIStart here
Store and retrieve an application secretSecret value and its versionsExplicit Http calls or Secrets convenience methods
Sign, decrypt, or unwrap a data keyA versioned key ID, kidCryptographic operations
Manage an X.509 identityCertificate metadata and public DERDiscovery and export, import, or issuance
Sign a PDF, XML document, or attached CMS fileCertificate plus remote signing keyDocument signing helpers
Recover an object or retain a protected backupDeleted objects or opaque backup blobsRecovery and backup/restore

Before making requests

Use Chilkat 11.6.0 or later and unlock the library. The explicit Http examples select Key Vault data-plane API 2026-04-01 at https://{vault_name}.vault.azure.net. Microsoft identifies that version as stable in its certificate SDK release history. Chilkat convenience helpers manage their own authentication and service API versions. These examples target Azure public-cloud vaults; Managed HSM and sovereign-cloud endpoints need their own configuration.

Direct examples load private qa_data/azure/keyvault.json. Set vault_name and the operation's inputs, such as secret_name, key_name, cert_name, or object_version. Authentication examples explain their credential fields. Create private input/output directories before running file-writing examples. Keep configuration, tokens, PFX files, secret values and backups outside public web content and source control.

Obtain a token for Key Vault and grant the identity the required data-plane permissions through the vault's configured Azure RBAC or access-policy model. A successful token exchange does not grant object access, and Contributor alone is insufficient for data-plane operations. Vault provisioning, networking and role assignments use separate management APIs. See Key Vault authentication and API version migration scope.

How requests map to Chilkat

Direct REST request handling
StepImplementation
AuthenticateRead qa_data/tokens/azureKeyVaultToken.json and set Http.AuthToken to its access token. Check the expires_at timestamp before each request.
Build the requestUse the HTTP method and resource path for the operation, with an explicit api-version. HttpReq sends a request object; HttpJson sends a JSON operation body.
Protect transportVerify TLS certificates, set connection/read timeouts and disable redirects. Validate service-provided URLs before forwarding bearer tokens.
Validate the responseCheck transport completion and HTTP status, then parse JSON strictly and require the expected fields. Status 202 is acceptance of an asynchronous operation; status 204 has no JSON body.
Follow pagesUse the service's nextLink without reconstructing its query. Check the same vault and expected collection path; continue through empty pages and detect cycles.

See the Key Vault REST reference and Chilkat Http reference. A certificate response's id, kid and sid refer to different resources. Use the returned key ID for signing; do not derive a key version from a certificate version. Retrieving public cer is different from retrieving the backing secret. See certificate composition and exportability.

Authentication and Access Tokens

The client-secret example uses a tenant-specific Entra v2 endpoint with scope=https://vault.azure.net/.default. Supply client_id, client_secret and the directory GUID tenant_id. Use the secret value, not its identifier. These credentials belong in a confidential application; client credentials do not issue a refresh token.

The VM managed-identity example calls the fixed IMDS endpoint with its Metadata header and no proxy. It supports an attached user-assigned identity through managed_identity_client_id; it is not an App Service token-endpoint example. The certificate flow signs a short-lived PS256 assertion using a registered application certificate. Federation instead exchanges a fresh token projected by a trusted workload runtime after the Entra federation trust is configured.

Each producer saves access_token and UTC expires_at to the shared private token file. The certificate-authentication PFX is separate from certificates stored in the vault. See client-credentials exchanges, VM managed identity, and certificate assertions.

Token Caching and Read Retries

The cache example reuses a token only when it has more than 60 seconds remaining and its tenant, client ID and Key Vault resource match. Otherwise it obtains a replacement with client credentials. It permits one renewal after a 401 response and at most five attempts for the certificate GET. The authentication request uses a separate Http instance.

For selected transient HTTP responses, it honors numeric or HTTP-date Retry-After, adds jitter, and stops rather than shortening a requested wait above 30 seconds. Transport failures stop. This is a single-caller cache; concurrent applications need synchronization and atomic replacement. The other direct examples check expiry and stop instead of automatically refreshing. Do not apply the read-retry loop unchanged to creates, imports, rotations or destructive operations. See Key Vault throttling guidance.

Secrets with Http

Use secret_name for an identity and object_version for a specific version. Setting a value creates a new version, including under an existing name. The set example reads private qa_data/azure/secret-value.json; the get example writes a new private qa_output/secret-value.json. Empty strings and Unicode are preserved, and values are not printed.

Set list_versions=false to enumerate identities or true to enumerate one secret's versions. Listing returns metadata, not secret values. The metadata example PATCHes the selected version's explicit enabled state and replaces tags with purpose=Example, without creating a new value. Merge existing tags yourself if they must be retained. Requires the appropriate secrets/set, get or list permissions. See Set Secret and Update Secret.

Secrets Convenience API

These existing examples use Secrets.Location="azure_key_vault" and SetBootstrapSecret. Their bootstrap JSON contains tenant ID, client ID and client secret; it is separate from the direct Http token file. Their secret identifiers use fields such as appName, service, domain, username and vaultName. Follow the example's naming convention rather than treating it as a direct versioned REST resource ID.

The local-manager bootstrap uses Windows Credentials Manager or Apple Keychain. On other platforms, use the in-memory bootstrap and select Location="memory" when consuming it. Some of these older convenience examples display secret contents or diagnostic text for demonstration; remove that output before production use. See the Chilkat Secrets reference.

Key Inventory, Creation, and Rotation

Create software-protected RSA-2048 or EC P-256 keys using key_name and key_type. Choose key_purpose="sign" for sign/verify, or "encrypt" for RSA encryption and wrapping operations. The key's key_ops constrain its use; they do not grant permissions to the caller. Creation under an existing name produces another version.

List identities or versions with list_versions. The rotation example reads the policy, replaces it with expiry P90D and rotation after P60D, then immediately rotates once. That replacement removes previous notification actions. Retain old versioned key IDs for existing signatures and encrypted data; rotation does not re-encrypt or rewrap them. See Create Key and rotation policy.

Signing, Encryption, and Key Wrapping

The certificate-based RS256 example retrieves a pinned certificate version and uses its returned backing kid. The PS256 and ES256 examples retrieve a key's public JWK by explicit key_name and object_version. All three sign a SHA-256 digest remotely and verify locally. RS256 uses RSA PKCS#1 v1.5; PS256 uses RSA-PSS with a 32-byte salt; ES256 uses P-256 and a fixed-width 64-byte r||s signature.

The service's signing values use base64url. Certificate cer and the issued-chain x5c use standard base64. Avoid hashing a message twice or confusing raw ECDSA signatures with ASN.1 DER. See Sign.

The RSA-OAEP-256 examples either encrypt/decrypt a small payload or wrap/unwrap a newly generated 32-byte AES key. They check the returned key ID and recovered bytes without printing plaintext or key material. RSA is not bulk-file encryption. For an envelope-encryption application, preserve the wrapped key, exact versioned kid, algorithm, nonce and authentication tag with the ciphertext. See Wrap Key.

Find, Retrieve, and Export Certificates

Certificate listing covers identities and latest-version metadata. Use the version-list example for history; use an explicit version when a workload must remain pinned. Retrieving the latest version does not search backward for one that is enabled and unexpired.

The local-certificate search follows identity pages and version pages, uses x5t as a candidate thumbprint, then compares the full DER certificate before reporting the first exact match. SHA-1 here is a lookup value, not a signature algorithm or a trust decision. Nested page data is copied before subsequent requests replace the response JSON.

Public export requires certificates/get and writes qa_output/public-certificate.cer without retrieving the backing secret/private key. Parsing a certificate does not validate its trust chain or revocation. See Get Certificate and Get Certificate Versions.

Import a PFX Certificate

Both examples load qa_data/pfx/myCertAndKey.pfx, read string pfx_password from private configuration, and validate the returned leaf against the source certificate. They inspect the public JWK for supported RSA/NIST EC key types rather than exporting a private JWK for inspection. Import under an existing certificate name creates a new version.

The explicit Http import selects a nonexportable policy and disables key reuse. Cert.UploadToCloud uses the helper's policy and authentication; choose the explicit example when exportability or API-version control is required. Its service identifier is azure-keyvault, whereas SetCloudSigner uses azure_keyvault. Preserve a protected local backup and reconcile an uncertain response before rerunning. Requires certificates/import. See Import Certificate.

Certificate Issuance and Policies

Set cert_name and certificate_subject. The creation examples use a nonexportable RSA-2048 key, no key reuse and 12-month validity. Issuer Self creates a self-signed certificate; issuer Unknown leaves an external-CA request pending. HTTP 202 means accepted. The examples poll the fixed pending path with attempt and elapsed-time bounds; after a timeout, resume reads instead of repeating creation.

The external-CA example verifies and exports qa_output/request.csr. Submit it to your CA separately, then put the issued chain in qa_data/azure/issued-chain.json as an x5c array of standard-base64 DER, leaf first. Merge validates the saved CSR signature and leaf public-key match, expects HTTP 201, and checks the returned certificate. It does not locally establish full CA-chain trust. See Create Certificate and Merge Certificate.

The policy example replaces lifetime actions with EmailContacts at 80 percent of validity. Configure contacts separately. This is a notification policy change, not automatic renewal or a rewrite of the current certificate DER.

PDF, XMLDSig, and CAdES Signing

Load the matching public certificate from qa_data/certs/myCert.cer and provide explicit cert_version plus client credentials for Cert.SetCloudSigner. Chilkat builds the document locally and asks Key Vault to sign its digest. The helper manages its own token flow and service API version; it does not consume the direct Http token cache.

The PDF example uses SHA-256 without claiming long-term validation. The XML example signs the SOAP Body using XMLDSig, exclusive canonicalization and SHA-256, then verifies the signature and references before saving; it does not create XAdES qualifying properties or sign the SOAP headers. The attached CAdES-BES example creates a .p7m with signingCertificateV2. These examples do not add a TSA timestamp or establish certificate trust/revocation. See SetCloudSigner.

Soft Delete and Recovery

Choose object_kind from keys, secrets or certificates and set object_name. Delete requires allow_delete=true and affects all versions under that name; deleting a certificate also affects its backing key and secret. It does not delete the vault. Record the returned recoveryId and inspect deleted-object state; visibility can be delayed.

The deleted-object example paginates results and reads the selected object. It performs recovery only with allow_recover=true. A successful recovery response does not guarantee immediate availability to every consumer. Purged objects cannot be recovered. See soft-delete and recovery behavior.

Protected Backup and Restore

Backup saves an opaque protected blob plus kind/name metadata to a new private qa_output/keyvault-backup.json. This is not a portable plaintext key export. For restore, copy it to qa_data/azure/keyvault-backup.json, choose the destination vault and matching kind/name, and set allow_restore=true.

The service enforces backup compatibility, subscription/geographic boundaries, version limits and destination-name conflicts. Restore does not rename or merge into an existing object. The examples keep blobs private and refuse to overwrite an existing backup output. See Key Vault backup and restore guidance.

Permanent Purge

Purge is irreversible. The separate purge example requires allow_purge=true and confirm_purge_name exactly matching object_name. It reads the deleted object before issuing DELETE and expects HTTP 204 without a JSON body.

Grant purge permission only when needed. Purge protection and retention can block the operation; a higher-privilege identity does not bypass purge protection. Do not use purge as routine retry or conflict cleanup. See purge protection.

Troubleshooting

Checks for common integration failures
SymptomWhat to check
401 or expired tokenCheck tenant, Key Vault audience, token expiry and clock accuracy. Use the correct token producer; direct Http, cloud-signing helpers and Secrets bootstrap are separate integrations.
403Check object-level permissions, the vault's RBAC/access-policy model, and firewall/private-endpoint access. Obtaining a token is not proof of authorization.
404 or delayed recovery visibilityCheck vault, resource kind, name and explicit version. Distinguish active and deleted-object paths. Retry a delayed read without repeating the preceding mutation.
429 or transient failureUse the bounded read-retry example, respecting Retry-After. Reconcile uncertain mutations before repeating them.
Signature or key-type mismatchMatch algorithm, curve, digest, encoding and versioned key ID. Use a certificate's returned kid and keep raw ECDSA distinct from DER.
Certificate issuance remains pendingResume bounded GET polling. External-CA issuance waits for an issued chain and merge; do not create another request merely because a poll timed out.
Output file already existsChoose a new private path or deliberately archive the previous output. Secret, backup, CSR and public-certificate exports refuse to overwrite; token caches intentionally replace their files.
Unexpected JSON or statusCheck transport and status before parsing. Keep request IDs for diagnosis without exposing full token-bearing responses, secret values, PFX data or private logs.