Java
Java
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 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();
// Build the JWS protected header. The "alg" member names the signature algorithm.
CkJsonObject header = new CkJsonObject();
header.UpdateString("alg","HS256");
// Set the protected header for signer index 0. The protected header is integrity-protected: it is
// covered by the signature.
success = jws.SetProtectedHeader(0,header);
if (success == false) {
System.out.println(jws.lastErrorText());
return;
}
System.out.println("Protected header set.");
}
}