PowerBuilder
PowerBuilder
Load and Validate a JWS from a String
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.LoadJws, which loads a JWS from its compact serialization string. The example then supplies the MAC key and validates the signature.
Background. Validate returns 1 when the signature or MAC is cryptographically valid, 0 when it is not, or a negative value on error. The key for the signer index 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 HMAC key for signer 0, then validate the signature. Validate returns 1 when the
// signature is cryptographically valid, 0 when it is not, or a negative value on error.
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
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