Classic ASP
Classic ASP
Validate a JWS with a Public Key
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.SetPublicKey, which sets the public key used to validate a signature of a loaded JWS.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. The public key verifies a signature created with the corresponding private key. Validate returns 1 when valid, 0 when not, or a negative value on error.
Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
set jws = Server.CreateObject("Chilkat.Jws")
' Load the JWS compact serialization.
jwsCompact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
success = jws.LoadJws(jwsCompact)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( jws.LastErrorText) & "</pre>"
Response.End
End If
' The file path is relative to the application's current working directory. An absolute path
' may also be used. Supply the path appropriate to your own environment.
' Load the signer's public key and set it for validating signature 0.
set pubKey = Server.CreateObject("Chilkat.PublicKey")
success = pubKey.LoadFromFile("qa_data/signer_pubkey.pem")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pubKey.LastErrorText) & "</pre>"
Response.End
End If
success = jws.SetPublicKey(0,pubKey)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( jws.LastErrorText) & "</pre>"
Response.End
End If
' Validate the signature. Validate returns 1 when valid, 0 when not, or a negative value on error.
v = jws.Validate(0)
If (v < 0) Then
Response.Write "<pre>" & Server.HTMLEncode( jws.LastErrorText) & "</pre>"
Response.End
End If
If (v <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "The signature is not valid.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "The signature is valid.") & "</pre>"
%>
</body>
</html>