Java
Chilkat2 Java
Get the Entire Loaded JWE Structure
See more JSON Web Encryption (JWE) Examples
Demonstrates Jwe.GetHeader, which copies the entire currently loaded JWE structure into a JsonObject.
Background. This is the full JWE representation, not a decoded or merged JOSE header. It can contain the protected, unprotected, and per-recipient header material.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Jwe;
public class ChilkatExample {
public static void main(String[] args) {
Jwe jwe = new Jwe();
// Load the JWE.
String jweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>";
try {
jwe.loadJwe(jweCompact);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Copy the entire loaded JWE structure into a JsonObject. This is the full JWE representation, not a
// decoded or merged JOSE header.
JsonObject json = new JsonObject();
try {
jwe.getHeader(json);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
json.setEmitCompact(false);
System.out.println(json.emit());
}
}