Java
Java
Get a JWS Protected Header
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.GetProtectedH, which copies the decoded protected header of a signature into a JsonObject.
Background. The protected header is integrity-protected by the signature. Inspecting it (for example the
alg value) is useful before deciding how to validate.Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
CkJws jws = new CkJws();
// Load the JWS compact serialization.
String jwsCompact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>";
success = jws.LoadJws(jwsCompact);
if (success == false) {
System.out.println(jws.lastErrorText());
return;
}
// Copy the decoded protected header of signature 0 into a JsonObject.
CkJsonObject json = new CkJsonObject();
success = jws.GetProtectedH(0,json);
if (success == false) {
System.out.println(jws.lastErrorText());
return;
}
json.put_EmitCompact(false);
System.out.println(json.emit());
}
}