PureBasic
PureBasic
Set the JWS Protected Header
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.SetProtectedHeader, which sets the integrity-protected header for a signer from a JsonObject. The header specifies the signature algorithm (alg).
Background. The protected header is covered by the signature, so it cannot be altered without invalidating the JWS. It is configured before creating the JWS.
Chilkat PureBasic Downloads
IncludeFile "CkJws.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 0
jws.i = CkJws::ckCreate()
If jws.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Build the JWS protected header. The "alg" member names the signature algorithm.
header.i = CkJsonObject::ckCreate()
If header.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(header,"alg","HS256")
; Set the protected header for signer index 0. The protected header is integrity-protected: it is
; covered by the signature.
success = CkJws::ckSetProtectedHeader(jws,0,header)
If success = 0
Debug CkJws::ckLastErrorText(jws)
CkJws::ckDispose(jws)
CkJsonObject::ckDispose(header)
ProcedureReturn
EndIf
Debug "Protected header set."
CkJws::ckDispose(jws)
CkJsonObject::ckDispose(header)
ProcedureReturn
EndProcedure