Java
Java
Set the JWE Protected Header
See more JSON Web Encryption (JWE) Examples
Demonstrates Jwe.SetProtectedHeader, which sets the integrity-protected JWE header from a JsonObject. The header specifies the key-management algorithm (alg) and content-encryption algorithm (enc).
Background. The protected header is integrity-protected and applies to all recipients. It is configured before encrypting.
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;
CkJwe jwe = new CkJwe();
// Build the JWE protected header. The "alg" member names the key-management algorithm and the "enc"
// member names the content-encryption algorithm.
CkJsonObject header = new CkJsonObject();
header.UpdateString("alg","A256KW");
header.UpdateString("enc","A256GCM");
// Set the protected header on the JWE. The protected header is integrity-protected and applies to
// all recipients.
success = jwe.SetProtectedHeader(header);
if (success == false) {
System.out.println(jwe.lastErrorText());
return;
}
System.out.println("Protected header set.");
}
}