Sample code for 30+ languages & platforms
PureBasic

Set the JWS Payload from BinData

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.SetPayloadBd, which sets the payload to be signed from the binary bytes in a BinData.

Background. JWS (JSON Web Signature) integrity-protects a payload with a signature or MAC. The header alg names the algorithm; this example uses HMAC-SHA256 (HS256) with a symmetric MAC key.

Chilkat PureBasic Downloads

PureBasic
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

    ;  Set the payload from the binary bytes in a BinData.
    bdPayload.i = CkBinData::ckCreate()
    If bdPayload.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkBinData::ckAppendString(bdPayload,"Binary content to sign.","utf-8")

    success = CkJws::ckSetPayloadBd(jws,bdPayload)
    If success = 0
        Debug CkJws::ckLastErrorText(jws)
        CkJws::ckDispose(jws)
        CkBinData::ckDispose(bdPayload)
        ProcedureReturn
    EndIf

    Debug "Payload set."


    CkJws::ckDispose(jws)
    CkBinData::ckDispose(bdPayload)


    ProcedureReturn
EndProcedure