public static void generateWebToken() { try { key = new AesKey(ByteUtil.randomBytes(16)); webToken = new JsonWebEncryption(); webToken.setPayload("Hello David"); webToken.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW); webToken.setEncryptionMethodHeaderParameter( ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256); webToken.setKey(key); String encrypted = webToken.getCompactSerialization(); System.out.println("Hello David : Encrypted " + encrypted); webToken = new JsonWebEncryption(); webToken.setKey(key); webToken.setCompactSerialization(encrypted); System.out.println("Payload: " + webToken.getPayload()); } catch (JoseException ex) { ex.printStackTrace(); } }