Sample code for 30+ languages & platforms
Java

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

Chilkat2 Java
import com.chilkatsoft.chilkat2.BinData;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Jws;

public class ChilkatExample {

    public static void main(String[] args) {
        Jws jws = new Jws();

        // Load the JWS compact serialization.
        String jwsCompact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>";
        try {
            jws.loadJws(jwsCompact);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Get the JWS payload as raw bytes into a BinData.
        BinData bdPayload = new BinData();
        try {
            jws.getPayloadBd(bdPayload);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Payload is " + bdPayload.getNumBytes() + " bytes.");
    }
}