AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
$oJws = ObjCreate("Chilkat.Jws")
; Load the JWS compact serialization.
Local $sJwsCompact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
$bSuccess = $oJws.LoadJws($sJwsCompact)
If ($bSuccess = False) Then
ConsoleWrite($oJws.LastErrorText & @CRLF)
Exit
EndIf
; 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.
$oPubKey = ObjCreate("Chilkat.PublicKey")
$bSuccess = $oPubKey.LoadFromFile("qa_data/signer_pubkey.pem")
If ($bSuccess = False) Then
ConsoleWrite($oPubKey.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oJws.SetPublicKey(0,$oPubKey)
If ($bSuccess = False) Then
ConsoleWrite($oJws.LastErrorText & @CRLF)
Exit
EndIf
; Validate the signature. Validate returns 1 when valid, 0 when not, or a negative value on error.
Local $iV = $oJws.Validate(0)
If ($iV < 0) Then
ConsoleWrite($oJws.LastErrorText & @CRLF)
Exit
EndIf
If ($iV <> 1) Then
ConsoleWrite("The signature is not valid." & @CRLF)
Exit
EndIf
ConsoleWrite("The signature is valid." & @CRLF)