PowerBuilder
PowerBuilder
Load and Validate a JWS from a StringBuilder
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.LoadJwsSb, which loads a JWS from a StringBuilder (here read from a file). The example then supplies the MAC key and validates the signature.
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. Validate returns 1 when the signature or MAC is cryptographically valid, 0 when it is not, or a negative value on error.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Jws
oleobject loo_SbJws
integer li_BLoaded
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
// 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 JWS text from a file into a StringBuilder.
loo_SbJws = create oleobject
li_rc = loo_SbJws.ConnectToNewObject("Chilkat.StringBuilder")
li_BLoaded = loo_SbJws.LoadFile("qa_data/message.jws","utf-8")
if li_BLoaded <> 1 then
Write-Debug "Failed to load the JWS file."
destroy loo_Jws
destroy loo_SbJws
return
end if
// Load the JWS from the StringBuilder.
li_Success = loo_Jws.LoadJwsSb(loo_SbJws)
if li_Success = 0 then
Write-Debug loo_Jws.LastErrorText
destroy loo_Jws
destroy loo_SbJws
return
end if
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
destroy loo_SbJws
return
end if
v = loo_Jws.Validate(0)
if v < 0 then
Write-Debug loo_Jws.LastErrorText
destroy loo_Jws
destroy loo_SbJws
return
end if
if v <> 1 then
Write-Debug "The signature is not valid."
destroy loo_Jws
destroy loo_SbJws
return
end if
Write-Debug "The signature is valid."
destroy loo_Jws
destroy loo_SbJws