PureBasic
PureBasic
Get the JWS Payload into BinData
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.GetPayloadBd, which writes the payload of a loaded JWS as raw bytes into a BinData.
Background. This is used when the payload is binary. In practice, validate the signature before trusting the payload.
Chilkat PureBasic Downloads
IncludeFile "CkJws.pb"
IncludeFile "CkBinData.pb"
Procedure ChilkatExample()
success.i = 0
jws.i = CkJws::ckCreate()
If jws.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Load the JWS compact serialization.
jwsCompact.s = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
success = CkJws::ckLoadJws(jws,jwsCompact)
If success = 0
Debug CkJws::ckLastErrorText(jws)
CkJws::ckDispose(jws)
ProcedureReturn
EndIf
; Get the JWS payload as raw bytes into a BinData.
bdPayload.i = CkBinData::ckCreate()
If bdPayload.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkJws::ckGetPayloadBd(jws,bdPayload)
If success = 0
Debug CkJws::ckLastErrorText(jws)
CkJws::ckDispose(jws)
CkBinData::ckDispose(bdPayload)
ProcedureReturn
EndIf
Debug "Payload is " + Str(CkBinData::ckNumBytes(bdPayload)) + " bytes."
CkJws::ckDispose(jws)
CkBinData::ckDispose(bdPayload)
ProcedureReturn
EndProcedure