Azure Key Vault: List Certificate Versions
See more Azure Key Vault Examples
Requires Chilkat 11.6.0 or later. Keep qa_data/azure/keyvault.json and token/PFX files private, outside web content and source control, with access restricted to the application identity. Use placeholders replaced by your configuration, never commit credentials. Create output directories before running file-writing examples. These examples target Azure public-cloud vaults, not Managed HSM or sovereign-cloud endpoints.
Uses HTTPS and Key Vault data-plane API 2026-04-01. Configure vault_name and first run the client-credentials token example. It writes access_token and an expires_at UTC timestamp to qa_data/tokens/azureKeyVaultToken.json. Each request checks expiration; refresh is explicit. The sample stops on errors and does not retry. Production callers should handle 429/Retry-After and transient failures with bounded backoff, and reconcile uncertain writes. Redirects are disabled.
Set list_versions=true and cert_name to list historical versions, or false for identities. Requires certificates/list. Shows IDs only, follows guarded continuation links and handles empty pages. This is a standalone metadata inventory; it does not retrieve private keys.
Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
set stringCompare = Server.CreateObject("Chilkat.StringBuilder")
' Assumes Chilkat is unlocked. See Global Unlock Sample.
' Keep this configuration private, outside public web content and source control.
set config = Server.CreateObject("Chilkat.JsonObject")
config.Strict = 1
success = config.LoadFile("qa_data/azure/keyvault.json")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not load private Key Vault configuration.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(config.StringOf("vault_name"))
stringMatch1 = stringCompare.ContentsEqual("",1)
If ((config.JsonTypeOf("vault_name") <> 1) Or (stringMatch1 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid vault_name.") & "</pre>"
Response.End
End If
set validate1 = Server.CreateObject("Chilkat.StringBuilder")
set alphabet1 = Server.CreateObject("Chilkat.StringBuilder")
success = validate1.Append(config.StringOf("vault_name"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not validate vault_name.") & "</pre>"
Response.End
End If
success = alphabet1.Append("abcdefghijklmnopqrstuvwxyz0123456789-")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not initialize validation.") & "</pre>"
Response.End
End If
If ((validate1.Length < 3) Or (validate1.Length > 24)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid vault_name length.") & "</pre>"
Response.End
End If
charIndex1 = 0
Do While (charIndex1 < validate1.Length)
If (alphabet1.Contains(validate1.GetRange(charIndex1,1,0),1) <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid character in vault_name.") & "</pre>"
Response.End
End If
charIndex1 = charIndex1 + 1
Loop
set vaultName = Server.CreateObject("Chilkat.StringBuilder")
success = vaultName.Append(config.StringOf("vault_name"))
set letters = Server.CreateObject("Chilkat.StringBuilder")
success = letters.Append("abcdefghijklmnopqrstuvwxyz")
If ((letters.Contains(vaultName.GetRange(0,1,0),1) <> 1) Or (vaultName.EndsWith("-",1) = 1) Or (vaultName.Contains("--",1) = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid vault_name.") & "</pre>"
Response.End
End If
set origin = Server.CreateObject("Chilkat.StringBuilder")
success = origin.Append("https://")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = origin.Append(config.StringOf("vault_name"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = origin.Append(".vault.azure.net")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
http.FollowRedirects = 0
http.ConnectTimeout = 20
http.ReadTimeout = 60
http.VerboseLogging = 0
ERROR: ASP example cannot use request or response as a variable name.
ERROR: ASP example cannot use request or response as a variable name.
ERROR: ASP example cannot use request or response as a variable name.
set result = Server.CreateObject("Chilkat.JsonObject")
result.Strict = 1
' First run Get a Key Vault access token.
set token = Server.CreateObject("Chilkat.JsonObject")
token.Strict = 1
success = token.LoadFile("qa_data/tokens/azureKeyVaultToken.json")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not read the private token file.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(token.StringOf("access_token"))
stringMatch2 = stringCompare.ContentsEqual("",1)
If ((token.JsonTypeOf("access_token") <> 1) Or (stringMatch2 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid access_token.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(token.StringOf("expires_at"))
stringMatch3 = stringCompare.ContentsEqual("",1)
If ((token.JsonTypeOf("expires_at") <> 1) Or (stringMatch3 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid expires_at.") & "</pre>"
Response.End
End If
set expires = Server.CreateObject("Chilkat.CkDateTime")
set now = Server.CreateObject("Chilkat.CkDateTime")
success = expires.SetFromTimestamp(token.StringOf("expires_at"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid token expiration.") & "</pre>"
Response.End
End If
http.AuthToken = token.StringOf("access_token")
set collection = Server.CreateObject("Chilkat.StringBuilder")
success = collection.Append(origin.GetAsString())
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = collection.Append("/certificates")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
' Set list_versions=true to enumerate one object's versions instead of identities.
If (config.HasMember("list_versions") = 1) Then
If (config.JsonTypeOf("list_versions") <> 5) Then
Response.Write "<pre>" & Server.HTMLEncode( "list_versions must be boolean.") & "</pre>"
Response.End
End If
If (config.BoolOf("list_versions") = 1) Then
success = stringCompare.SetString(config.StringOf("cert_name"))
stringMatch4 = stringCompare.ContentsEqual("",1)
If ((config.JsonTypeOf("cert_name") <> 1) Or (stringMatch4 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid cert_name.") & "</pre>"
Response.End
End If
set validate46 = Server.CreateObject("Chilkat.StringBuilder")
set alphabet46 = Server.CreateObject("Chilkat.StringBuilder")
success = validate46.Append(config.StringOf("cert_name"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not validate cert_name.") & "</pre>"
Response.End
End If
success = alphabet46.Append("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not initialize validation.") & "</pre>"
Response.End
End If
If ((validate46.Length < 1) Or (validate46.Length > 127)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid cert_name length.") & "</pre>"
Response.End
End If
charIndex46 = 0
Do While (charIndex46 < validate46.Length)
If (alphabet46.Contains(validate46.GetRange(charIndex46,1,0),1) <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid character in cert_name.") & "</pre>"
Response.End
End If
charIndex46 = charIndex46 + 1
Loop
success = collection.Append("/")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not build path.") & "</pre>"
Response.End
End If
success = collection.Append(config.StringOf("cert_name"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not build path.") & "</pre>"
Response.End
End If
success = collection.Append("/versions")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not build path.") & "</pre>"
Response.End
End If
End If
End If
set pagePrefix = Server.CreateObject("Chilkat.StringBuilder")
success = pagePrefix.Append(collection.GetAsString())
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = pagePrefix.Append("?")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
set firstPage = Server.CreateObject("Chilkat.StringBuilder")
success = firstPage.Append(pagePrefix.GetAsString())
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = firstPage.Append("api-version=2026-04-01&maxresults=25")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
set itemsSeen = Server.CreateObject("Chilkat.Hashtable")
set itemsItems = Server.CreateObject("Chilkat.JsonArray")
set itemsView = Server.CreateObject("Chilkat.JsonArray")
set itemsEntry = Server.CreateObject("Chilkat.JsonObject")
itemsCurrentUrl = firstPage.GetAsString()
itemsPages = 0
itemsMore = 1
Do While (itemsMore = 1)
If (itemsPages = 10000) Then
Response.Write "<pre>" & Server.HTMLEncode( "Page bound reached; enumeration is incomplete.") & "</pre>"
Response.End
End If
If (itemsSeen.Contains(itemsCurrentUrl) = 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Repeated nextLink; enumeration is incomplete.") & "</pre>"
Response.End
End If
success = itemsSeen.AddStr(itemsCurrentUrl,"seen")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not track pagination.") & "</pre>"
Response.End
End If
itemsPages = itemsPages + 1
success = now.SetFromCurrentSystemTime()
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not read current time.") & "</pre>"
Response.End
End If
If (expires.DiffSeconds(now) <= 60) Then
Response.Write "<pre>" & Server.HTMLEncode( "Token is expired or near expiration. Obtain a new token before continuing.") & "</pre>"
Response.End
End If
success = http.HttpReq(itemsCurrentUrl,request,response)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Request did not complete; inspect diagnostics privately.") & "</pre>"
Response.End
End If
If (response.StatusCode <> 200) Then
Response.Write "<pre>" & Server.HTMLEncode( "HTTP status: " & response.StatusCode) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Request ID: " & response.GetHeaderField("x-ms-request-id")) & "</pre>"
' Do not print full response bodies, tokens, or diagnostic logs.
Response.Write "<pre>" & Server.HTMLEncode( "Request failed. Inspect private diagnostics; reconcile writes before retrying.") & "</pre>"
Response.End
End If
success = result.Load(response.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a well-formed JSON response.") & "</pre>"
Response.End
End If
If (result.JsonTypeOf("value") <> 4) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a value array.") & "</pre>"
Response.End
End If
success = result.ArrayOf2("value",itemsView)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not read certificate array.") & "</pre>"
Response.End
End If
success = itemsItems.Load(itemsView.Emit())
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not detach the page before nested requests.") & "</pre>"
Response.End
End If
itemsMore = 0
If (result.HasMember("nextLink") = 1) Then
If (result.JsonTypeOf("nextLink") <> 6) Then
success = stringCompare.SetString(result.StringOf("nextLink"))
stringMatch5 = stringCompare.ContentsEqual("",1)
If ((result.JsonTypeOf("nextLink") <> 1) Or (stringMatch5 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid nextLink.") & "</pre>"
Response.End
End If
itemsCurrentUrl = result.StringOf("nextLink")
set itemsNext = Server.CreateObject("Chilkat.StringBuilder")
success = itemsNext.Append(itemsCurrentUrl)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
If ((itemsNext.StartsWith(pagePrefix.GetAsString(),1) <> 1) Or (itemsNext.Contains("#",1) = 1) Or (itemsNext.Contains("\",1) = 1) Or (itemsNext.Contains(vbCr,1) = 1) Or (itemsNext.Contains(vbLf,1) = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Unsafe pagination URL; stopped before sending a token.") & "</pre>"
Response.End
End If
itemsMore = 1
End If
End If
itemsIndex = 0
Do While (itemsIndex < itemsItems.Size)
success = itemsItems.ObjectAt2(itemsIndex,itemsEntry)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid item.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(itemsEntry.StringOf("id"))
stringMatch6 = stringCompare.ContentsEqual("",1)
If ((itemsEntry.JsonTypeOf("id") <> 1) Or (stringMatch6 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid id.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Resource ID: " & itemsEntry.StringOf("id")) & "</pre>"
itemsIndex = itemsIndex + 1
Loop
Loop
Response.Write "<pre>" & Server.HTMLEncode( "Example completed.") & "</pre>"
%>
</body>
</html>