Visual FoxPro
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loJws
LOCAL loSbJws
LOCAL lnBLoaded
LOCAL lcBase64Key
LOCAL v
lnSuccess = 0
loJws = CreateObject('Chilkat.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.
* Load the JWS text from a file into a StringBuilder.
loSbJws = CreateObject('Chilkat.StringBuilder')
lnBLoaded = loSbJws.LoadFile("qa_data/message.jws","utf-8")
IF (lnBLoaded <> 1) THEN
? "Failed to load the JWS file."
RELEASE loJws
RELEASE loSbJws
CANCEL
ENDIF
* Load the JWS from the StringBuilder.
lnSuccess = loJws.LoadJwsSb(loSbJws)
IF (lnSuccess = 0) THEN
? loJws.LastErrorText
RELEASE loJws
RELEASE loSbJws
CANCEL
ENDIF
lcBase64Key = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU="
lnSuccess = loJws.SetMacKey(0,lcBase64Key,"base64")
IF (lnSuccess = 0) THEN
? loJws.LastErrorText
RELEASE loJws
RELEASE loSbJws
CANCEL
ENDIF
v = loJws.Validate(0)
IF (v < 0) THEN
? loJws.LastErrorText
RELEASE loJws
RELEASE loSbJws
CANCEL
ENDIF
IF (v <> 1) THEN
? "The signature is not valid."
RELEASE loJws
RELEASE loSbJws
CANCEL
ENDIF
? "The signature is valid."
RELEASE loJws
RELEASE loSbJws