Azure Key Vault: Sign and Locally Verify PS256
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 key_name and object_version. Requires keys/get and keys/sign. Uses the public JWK from the pinned key version. Sends a SHA-256 digest as base64url; local verification does not call keys/verify. PS256 uses RSA-PSS with a 32-byte salt.
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")
success = stringCompare.SetString(config.StringOf("key_name"))
stringMatch4 = stringCompare.ContentsEqual("",1)
If ((config.JsonTypeOf("key_name") <> 1) Or (stringMatch4 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid key_name.") & "</pre>"
Response.End
End If
set validate20 = Server.CreateObject("Chilkat.StringBuilder")
set alphabet20 = Server.CreateObject("Chilkat.StringBuilder")
success = validate20.Append(config.StringOf("key_name"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not validate key_name.") & "</pre>"
Response.End
End If
success = alphabet20.Append("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not initialize validation.") & "</pre>"
Response.End
End If
If ((validate20.Length < 1) Or (validate20.Length > 127)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid key_name length.") & "</pre>"
Response.End
End If
charIndex20 = 0
Do While (charIndex20 < validate20.Length)
If (alphabet20.Contains(validate20.GetRange(charIndex20,1,0),1) <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid character in key_name.") & "</pre>"
Response.End
End If
charIndex20 = charIndex20 + 1
Loop
set resourceBase = Server.CreateObject("Chilkat.StringBuilder")
success = resourceBase.Append(origin.GetAsString())
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = resourceBase.Append("/keys/")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = resourceBase.Append(config.StringOf("key_name"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(config.StringOf("object_version"))
stringMatch5 = stringCompare.ContentsEqual("",1)
If ((config.JsonTypeOf("object_version") <> 1) Or (stringMatch5 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid object_version.") & "</pre>"
Response.End
End If
set validate21 = Server.CreateObject("Chilkat.StringBuilder")
set alphabet21 = Server.CreateObject("Chilkat.StringBuilder")
success = validate21.Append(config.StringOf("object_version"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not validate object_version.") & "</pre>"
Response.End
End If
success = alphabet21.Append("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not initialize validation.") & "</pre>"
Response.End
End If
If ((validate21.Length < 1) Or (validate21.Length > 127)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid object_version length.") & "</pre>"
Response.End
End If
charIndex21 = 0
Do While (charIndex21 < validate21.Length)
If (alphabet21.Contains(validate21.GetRange(charIndex21,1,0),1) <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid character in object_version.") & "</pre>"
Response.End
End If
charIndex21 = charIndex21 + 1
Loop
set resourceId = Server.CreateObject("Chilkat.StringBuilder")
success = resourceId.Append(resourceBase.GetAsString())
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = resourceId.Append("/")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = resourceId.Append(config.StringOf("object_version"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
set getUrl = Server.CreateObject("Chilkat.StringBuilder")
success = getUrl.Append(resourceId.GetAsString())
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = getUrl.Append("?api-version=2026-04-01")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
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
ERROR: ASP example cannot use request or response as a variable name.
success = http.HttpReq(getUrl.GetAsString(),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( "Unexpected HTTP status; inspect request ID and diagnostics privately. Reconcile writes before retrying.") & "</pre>"
Response.End
End If
success = result.Load(response.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid JSON response.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(result.StringOf("key.kid"))
stringMatch6 = stringCompare.ContentsEqual("",1)
If ((result.JsonTypeOf("key.kid") <> 1) Or (stringMatch6 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid key.kid.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(result.StringOf("key.kid"))
stringMatch7 = stringCompare.ContentsEqual(resourceId.GetAsString(),1)
If (stringMatch7 <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Response identifier does not match the requested version.") & "</pre>"
Response.End
End If
set jwk = Server.CreateObject("Chilkat.JsonObject")
success = result.ObjectOf2("key",jwk)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing key JWK.") & "</pre>"
Response.End
End If
set publicKey = Server.CreateObject("Chilkat.PublicKey")
success = publicKey.LoadFromString(jwk.Emit())
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not load public JWK.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(jwk.StringOf("kty"))
stringMatch8 = stringCompare.ContentsEqual("RSA",1)
If (stringMatch8 <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Wrong key type for this algorithm.") & "</pre>"
Response.End
End If
message = "Key Vault signing example"
set hash = Server.CreateObject("Chilkat.Crypt2")
hash.Charset = "utf-8"
hash.HashAlgorithm = "sha256"
hash.EncodingMode = "base64url"
digest = hash.HashStringENC(message)
If (hash.LastMethodSuccess <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not hash message.") & "</pre>"
Response.End
End If
set body = Server.CreateObject("Chilkat.JsonObject")
success = body.UpdateString("alg","PS256")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not set alg.") & "</pre>"
Response.End
End If
success = body.UpdateString("value",digest)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not set value.") & "</pre>"
Response.End
End If
set operationUrl = Server.CreateObject("Chilkat.StringBuilder")
success = operationUrl.Append(resourceId.GetAsString())
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
success = operationUrl.Append("/sign?api-version=2026-04-01")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not construct URL or identifier.") & "</pre>"
Response.End
End If
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.HttpJson("POST",operationUrl.GetAsString(),body,"application/json",response)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Request failed; reconcile uncertain writes before retrying.") & "</pre>"
Response.End
End If
If (response.StatusCode <> 200) Then
Response.Write "<pre>" & Server.HTMLEncode( "Unexpected HTTP status; inspect request ID and diagnostics privately. Reconcile writes before retrying.") & "</pre>"
Response.End
End If
success = result.Load(response.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid JSON response.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(result.StringOf("value"))
stringMatch9 = stringCompare.ContentsEqual("",1)
If ((result.JsonTypeOf("value") <> 1) Or (stringMatch9 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid value.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(result.StringOf("kid"))
stringMatch10 = stringCompare.ContentsEqual("",1)
If ((result.JsonTypeOf("kid") <> 1) Or (stringMatch10 = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid kid.") & "</pre>"
Response.End
End If
success = stringCompare.SetString(result.StringOf("kid"))
stringMatch11 = stringCompare.ContentsEqual(resourceId.GetAsString(),1)
If (stringMatch11 <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Response identifier does not match the requested version.") & "</pre>"
Response.End
End If
set validate28 = Server.CreateObject("Chilkat.StringBuilder")
set alphabet28 = Server.CreateObject("Chilkat.StringBuilder")
success = validate28.Append(result.StringOf("value"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not validate signature.") & "</pre>"
Response.End
End If
success = alphabet28.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not initialize validation.") & "</pre>"
Response.End
End If
If ((validate28.Length < 1) Or (validate28.Length > 10485760)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid signature length.") & "</pre>"
Response.End
End If
charIndex28 = 0
Do While (charIndex28 < validate28.Length)
If (alphabet28.Contains(validate28.GetRange(charIndex28,1,0),1) <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid character in signature.") & "</pre>"
Response.End
End If
charIndex28 = charIndex28 + 1
Loop
set verifier = Server.CreateObject("Chilkat.Rsa")
verifier.PkcsPadding = 0
verifier.PssSaltLen = 32
verifier.EncodingMode = "base64url"
verifier.Charset = "utf-8"
success = verifier.UsePublicKey(publicKey)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not select RSA public key.") & "</pre>"
Response.End
End If
success = verifier.VerifyStringENC(message,"sha256",result.StringOf("value"))
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "PSS signature verification failed.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Example completed.") & "</pre>"
%>
</body>
</html>