PowerBuilder
PowerBuilder
Validate a JWS Signature
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.Validate, which validates exactly one signature, identified by a zero-based index, using the key configured at that same index.
Background. Validate returns 1 when the signature or MAC is cryptographically valid, 0 when it is not, or a negative value on error. The verifying key must be provided before validating.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Jws
string ls_JwsCompact
string ls_Base64Key
integer v
li_Success = 0
loo_Jws = create oleobject
li_rc = loo_Jws.ConnectToNewObject("Chilkat.Jws")
if li_rc < 0 then
destroy loo_Jws
MessageBox("Error","Connecting to COM object failed")
return
end if
// Load the JWS compact serialization.
ls_JwsCompact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
li_Success = loo_Jws.LoadJws(ls_JwsCompact)
if li_Success = 0 then
Write-Debug loo_Jws.LastErrorText
destroy loo_Jws
return
end if
// Provide the key for signature 0 (here an HMAC key).
ls_Base64Key = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU="
li_Success = loo_Jws.SetMacKey(0,ls_Base64Key,"base64")
if li_Success = 0 then
Write-Debug loo_Jws.LastErrorText
destroy loo_Jws
return
end if
// Validate the signature identified by the zero-based index, using the key configured at that index.
// Validate returns 1 when the signature or MAC is cryptographically valid, 0 when it is not, or a
// negative value on error.
v = loo_Jws.Validate(0)
if v < 0 then
Write-Debug loo_Jws.LastErrorText
destroy loo_Jws
return
end if
if v <> 1 then
Write-Debug "The signature is not valid."
destroy loo_Jws
return
end if
Write-Debug "The signature is valid."
destroy loo_Jws