logo

Program Description | Document

Develop a secure communication system for the Rebellion using client and server programs.

15 Pages1603 Words24 Views
   

Added on  2022-08-11

About This Document

Na

Program Description | Document

Develop a secure communication system for the Rebellion using client and server programs.

   Added on 2022-08-11

ShareRelated Documents
Running Head: Program Description
Program Description
Name of the Student
Name of the University
Author Name
Program Description | Document_1
Client Class
Creating a package named soketprogaming1. In java, the package is a special type of mechanism that
helps to encapsulate a group of classes. The package will help us to prevent naming conflicts and help us
to search for a specific class among other classes. After creating a package, importing several classes by
using the import statement. These classes or packages are essentials to run the program. Importing
java.net.* to using networking application on the java code. java.io.* is basically used for input and
output. Importing MessageDigest of the security class provided every function the message-digest
algorithm. No Such Algorithm Exception is handle by the exception class. This exception can be thrown
when cryptographic algorithm expected but that program is not present in the program. These are the
most important packages that are used in the client class. In the client class, initializing socket and input-
output streams to execute the program. Creating a constructor to put the IP address and port number.
Then providing codes for establishing a connection for connecting a client to the server. Then creating
codes to send data to the server. By using buffer reader class reading data is coming from the server. To
read data from the keyboard by using Buffered Reader kb then closing the connection by using the close
connection for class. The main method is implemented in this class.
package soketprogaming1;
import java.net.*;
import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Base64;
import java.util.Scanner;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class Client
{
Program Description | Document_2
// initialize socket and input output streams
private Socket socket = null;
private byte[] key;
private DataInputStream input = null;
private DataOutputStream out = null;
private BufferedReader br;
private static SecretKeySpec secretKey;
static String address;
static int port;
static String userid1;
final String secretKey1 = "ssshhhhhhhhhhh!!!!";
long millis=System.currentTimeMillis();
java.util.Date date=new java.util.Date(millis);
// constructor to put ip address and port
public Client(String address, int port,String userid1) throws IOException
{
this.address=address;
this.port=port;
this.userid1=userid1;
MessageDigest sha = null;
// establish a connection
socket = new Socket(address, port);
System.out.println("Connected");
System.out.println(userid1);
System.out.println(date);
try {
Program Description | Document_3
key = userid1.getBytes("UTF-8");
sha = MessageDigest.getInstance("SHA-256");
key = sha.digest(key);
key= Arrays.copyOf(key, 16);
secretKey = new SecretKeySpec(key, "AES");
}
catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
e.printStackTrace();
}
// to send data to the server
DataOutputStream dos
= new DataOutputStream(
socket.getOutputStream());
// to read data coming from the server
BufferedReader br
= new BufferedReader(
new InputStreamReader(
socket.getInputStream()));
// to read data from the keyboard
BufferedReader kb
= new BufferedReader(
new InputStreamReader(System.in));
String str, str1;
// repeat as long as exit
Program Description | Document_4

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Client and Server Application | Report
|16
|1570
|21

Code for Proxy Cache Assignment - Desklib
|7
|1720
|105

Client Server System for Socket Programming | Desklib
|18
|1451
|253

Client Server Programming - Desklib
|9
|1289
|365

Client Server Programming Using RSA
|9
|1136
|384