Sample code for 30+ languages & platforms
Swift

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 Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    let jws = CkoJws()!

    //  Load the JWS compact serialization.
    var jwsCompact: String? = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
    success = jws.load(jwsStr: jwsCompact)
    if success == false {
        print("\(jws.lastErrorText!)")
        return
    }

    //  Get the JWS payload as raw bytes into a BinData.
    let bdPayload = CkoBinData()!
    success = jws.getPayloadBd(binData: bdPayload)
    if success == false {
        print("\(jws.lastErrorText!)")
        return
    }

    print("Payload is \(bdPayload.numBytes.intValue) bytes.")

}