Lianja
Lianja
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 Lianja Downloads
llSuccess = .F.
loJws = createobject("CkJws")
// 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.
loSbJws = createobject("CkStringBuilder")
llBLoaded = loSbJws.LoadFile("qa_data/message.jws","utf-8")
if (llBLoaded <> .T.) then
? "Failed to load the JWS file."
release loJws
release loSbJws
return
endif
// Load the JWS from the StringBuilder.
llSuccess = loJws.LoadJwsSb(loSbJws)
if (llSuccess = .F.) then
? loJws.LastErrorText
release loJws
release loSbJws
return
endif
lcBase64Key = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU="
llSuccess = loJws.SetMacKey(0,lcBase64Key,"base64")
if (llSuccess = .F.) then
? loJws.LastErrorText
release loJws
release loSbJws
return
endif
v = loJws.Validate(0)
if (v < 0) then
? loJws.LastErrorText
release loJws
release loSbJws
return
endif
if (v <> 1) then
? "The signature is not valid."
release loJws
release loSbJws
return
endif
? "The signature is valid."
release loJws
release loSbJws