throws Exception {
JWTClaimsSet claimsSet = new JWTClaimsSet();
claimsSet.setSubject("alice");
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), claimsSet);
JWSSigner signer = new MACSigner(key128);
signedJWT.sign(signer);
assertEquals(JWSObject.State.SIGNED, signedJWT.getState());
Payload payload = new Payload(signedJWT);
assertEquals(Payload.Origin.SIGNED_JWT, payload.getOrigin());
assertEquals(signedJWT, payload.toSignedJWT());
assertEquals(signedJWT, payload.toJWSObject());
JWEObject jweObject = new JWEObject(new JWEHeader(JWEAlgorithm.A128KW, EncryptionMethod.A128GCM), payload);
JWEEncrypter encrypter = new AESEncrypter(key128);
jweObject.encrypt(encrypter);
assertEquals(JWEObject.State.ENCRYPTED, jweObject.getState());
String compactEncoding = jweObject.serialize();
JWEDecrypter decrypter = new AESDecrypter(key128);
jweObject = JWEObject.parse(compactEncoding);
assertEquals(compactEncoding, jweObject.getParsedString());
jweObject.decrypt(decrypter);
payload = jweObject.getPayload();
signedJWT = payload.toSignedJWT();
assertEquals("alice", signedJWT.getJWTClaimsSet().getSubject());
}