Cryptography Reference
In-Depth Information
//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 server
output.write(ciphertext);
output.flush();
//Display same message in client output area
displayArea.append(“\n”+message);
enterField.setText(“”);
} catch (IOException ioe) {
displayArea.append(“\nError writing message”);
}
} else if (source==connectButton) {
if (connection!=null) { //Already connected-button press now means disconnect
try {
//Send final message of 0
byte[] lastMsg=new byte[1];
lastMsg[0]=0;
output.write(Ciphers.RSAEncipherWSalt
(lastMsg,BigIntegerMath.THREE,recipModulus,sr));
output.flush();
//close connection and IO streams, change some components
closeAll();
} catch (IOException ioe) {
displayArea.append(“\nError closing connection”);
}
} else {//Not connected-connect
//Get name of server to connect to
chatServer=serverField.getText();
displayArea.setText(“Attempting connection to “+chatServer);
try {
//Set up the socket
connection = new Socket(chatServer,55555);
displayArea.append
(“\nConnected to: “+connection.getInetAddress().getHostName());
//Set up the IO streams
output = new DataOutputStream(connection.getOutputStream());
output.flush();
Search WWH ::




Custom Search