Cryptography Reference
In-Depth Information
2.
The user clicked on the disconnect button. This sends a final one byte message of ZERO
(enciphered) to the recipient. This special message signifies that this is the last trans-
mission for the connection.
These cases are handled here in the actionPerformed() method.
public void actionPerformed(ActionEvent e) {
Object source=e.getSource();
//User pressed enter in message entry field-send it
if (source==enterField) {
//Get the message
message=e.getActionCommand();
try {
//Encipher the message
if (message.length()>plaintextBlockSize)
message=message.substring(0,plaintextBlockSize);
byte[] ciphertext=Ciphers.RSAEncipherWSalt
(message.getBytes(),BigIntegerMath.THREE,recipModulus,sr);
//Send to the client
output.write(ciphertext);
output.flush();
//Display same message in output area
displayArea.append(“\n”+message);
enterField.setText(“”);
} catch ( IOException ioe ) {
displayArea.append(“\nError writing message”);
}
//Server wishes disconnect from the client
} else if (source==disconnectButton) {
try {
byte[] lastMsg=new byte[1];
lastMsg[0]=0;
output.write(Ciphers.RSAEncipherWSalt
(lastMsg,BigIntegerMath.THREE,recipModulus,sr));
output.flush();
closeAll();
} catch (IOException ioe) {
displayArea.append(“\nError in disconnecting”);
}
}
}
Note that before a message is encrypted and sent, it may be truncated so that it does not
exceed the plaintext block size.
The go() method is where the server does most of its work. It continually loops (until
someone closes the application) listening for incoming connections. When the accept()
Search WWH ::




Custom Search