Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oJws
LOCAL oHeader
nSuccess := 0
oJws := CreateObject("Chilkat.Jws")
// Build the JWS protected header. The "alg" member names the signature algorithm.
oHeader := CreateObject("Chilkat.JsonObject")
oHeader:UpdateString("alg", "HS256")
// Set the protected header for signer index 0. The protected header is integrity-protected: it is
// covered by the signature.
nSuccess := oJws:SetProtectedHeader(0, oHeader)
IF (nSuccess == 0)
? oJws:LastErrorText
oJws:destroy()
oHeader:destroy()
RETURN
ENDIF
? "Protected header set."
oJws:destroy()
oHeader:destroy()