Java Reference
In-Depth Information
public
public void
void completed ( Response response )
{
Link next = response . getLink ( "next" );
String message = response . readEntity ( String . class );
try
try
{
JWEInput encrypted = new
new JWEInput ( message );
message = encrypted . decrypt ( secret ). readContent ( String . class );
}
catch
catch ( Exception ignore )
{
//e.printStackTrace();
}
System . out . println ();
System . out . print ( message );
System . out . println ();
System . out . print ( "> " );
client . target ( next ). request (). async (). get ( this
this );
}
@Override
public
public void
void failed ( Throwable throwable )
{
System . err . println ( "FAILURE!" );
}
});
The code then implements the receive loop we discussed in Chapter 27 . The difference is
that it uses the RESTEasy org.jboss.resteasy.jose.jwe.JWEInput class to decrypt the
received message. A JWEInput instance is initialized with the received text message. The
JWEInput.decrypt() method decrypts the JWE with the shared secret. The readContext()
method extracts the decrypted bytes into a String object that we can output to the console. If
the message is not a JWE or if the wrong secret is used, then the original received text mes-
sage is outputted to the console.
Let's now take a look at how sending a message has changed:
while
while ( true
true )
{
System . out . print ( "> " );
BufferedReader br = new
new BufferedReader
( new
new InputStreamReader ( System . in ));
String message = name + ": " + br . readLine ();
String encrypted = new
new JWEBuilder ()
. contentType ( MediaType . TEXT_PLAIN_TYPE )
Search WWH ::




Custom Search