CO3099/7099: Client Server Programming with RSA Encryption

Verified

Added on  2022/08/10

|9
|1136
|384
Project
AI Summary
This Java project focuses on building a secure client-server application utilizing the RSA algorithm for encryption and decryption. The system comprises four Java classes: `Server.java`, `Client.java`, `RSA.java`, and `Message.java`. `Server.java` establishes the server, enabling client connections via socket programming using a specified port. `Client.java` allows clients to connect to the server, providing a user ID and host information to establish a connection. `RSA.java` handles encryption and decryption of messages using the RSA algorithm, along with SHA-256 hashing of recipient user IDs for security. The `Message.java` class stores message details like encrypted messages, timestamps, and user IDs, employing getter and setter methods for data encapsulation. The program demonstrates the secure transmission of messages, where clients encrypt their messages before sending them to the server, which decrypts them for readability. The project includes socket programming for establishing the client and server communication.
tabler-icon-diamond-filled.svg

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
Running Head: Client Server Programming Using RSA
Client Server Programming Using RSA
Name of the Student
Name of the University
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
1Client Server Programming Using RSA
Client Server Programming Using RSA
This Java program is used to create a server and a client to send private message with
each other. In this Java program, there are four Java classes is used to perform the client server
programming. The first class called Server.java which is used to create a server by which clients
can interact with the server to communicate with each other.
The second class is used for the client where every client have to connect with the server
to send and receive messages from the server. The third Java class is used to perform the
encryption and decryption of the message using RSA algorithm. In this class all the encryption
and decryption methods are created to encrypt the message of the client and sends the encrypted
message to server for secure transition of the messages.
Every message is encrypted before sending it to the server and then if the server wants to
see the message then server decrypt the message using the public key. In this program a
message.java class is used to store all the messages and keys along with the user id of the client
if the server does not decrypt the message after it’s received the message from the client. All the
classes describe below.
Server.java:
Server.java is the most important class of this program because without this class all the
rest of the class is useless. Because the server is the every client is connected to the server by
their port number and host name. If this class does not exist, then the entire program stop
executing.
Document Page
2Client Server Programming Using RSA
For this program socket programming is used to create server and client because to
connect with other terminal or computer socket connection is used. Basically socket
programming means that both of the system, server and client have the information with each
other like network location and port. In Java socket is represented by Java.net.Socket.
ServerSocket ss=new ServerSocket(4567);
The above code is used to create the instance of Server Socket class and for the
communication between client and server 4567 port number is used. After creating an instance of
the server socket the server waits for the client for connection.
Socket s=ss.accept();
This above line of code is used to accept the client connection if the client tries to connect
to a server with the same port number, then the this accept () method returns an instance of the
socket.
Client.java
Client.java is a class which is used to create a client application for that it is necessary to
create an instance of socket by passing hostname, port number and the user id. In this program
the client and server both classes are running on the same machine so local host is used for
connection.
Socket s = new Socket(args[0], Integer.parseInt(args[1]));
String userID = args[2];
Document Page
3Client Server Programming Using RSA
The above lines of code are used to create an instance of the socket and hostname and
port number along with the user id is passed at the time of executing through a command
line argument.
java Client localhost 4567 alice
The above line is used to pass the host name and port number through the command line
for established the connection. If the port number or hostname does not match with the
server then the program gives an error and stops execution.
RSA.java
RSA.java is used to perform all the encryption and decryption operation of the message
which is transmitted between server and client. In this class the message is sent by the client is
encrypted by the method called byte [] encrypt. This byte [] encrypt method encrypts the
message using a key and send the message to the server. After receiving the message server can
decrypt the message to read what client sends by using byte [] decrypt method of RSA class.
In this class SHA-256 hash of the recipient user id is also generated and by using “public
String SHA256 ()” method. In this method the client user id is passed to generate SHA-256 hash
by using Message Digest predefine class.
In this class all the key generation, encryption, decryption of the message and SHA-256
hash are generated and passed to different classed like client.java, server.java and message.java.
Message.java
Message.java class is used to store all the necessary details of the program like SHA-256
Hash, encrypted message with the user id and other relevant information about this program.
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
4Client Server Programming Using RSA
Getter and setter methods are used to encapsulate all the information of important
information is passed through getter and setter methods. Some of the examples of getter and
setter methods are given below:
public static String getRecipientHash() {
return recipientHash;
}
The above getter method is for recpirntHash which is returning the SHA-256 Hash of the
user id.
public static void setRecipientHash(String recipientHash) {
Message.recipientHash = recipientHash;
}
The above code is in the setter method of recipient Hash.
public static Date getTimestamp() {
return timestamp;
}
public static void setTimestamp(Date timestamp) {
Message.timestamp = timestamp;
}
Document Page
5Client Server Programming Using RSA
The above getter setter method is used to encapsulate timestamp of messages sends by
client and server.
Output
Output-1: Server Stated and connected with Client
Output-2: Client connected with server and ready to send messge
Document Page
6Client Server Programming Using RSA
Output-3: Alice Client sending message to client
Output-4: Server receives encrypted message from the client
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7Client Server Programming Using RSA
Output-5: Message decrypted by server and the message is now readable
Document Page
8Client Server Programming Using RSA
Bibliography
Appel, A.W., 2015. Verification of a cryptographic primitive: SHA-256. ACM Transactions on
Programming Languages and Systems (TOPLAS), 37(2), pp.1-31.
Kak, A., 2015. Lecture 12: Public-Key Cryptography and the RSA Algorithm. Purdue
University, Mar, 31.
Maata, R.L.R., Cordova, R., Sudramurthy, B. and Halibas, A., 2017, December. Design and
Implementation of Client-Server Based Application using Socket Programming in a
Distributed Computing Environment. In 2017 IEEE International Conference on
Computational Intelligence and Computing Research (ICCIC) (pp. 1-4). IEEE.
chevron_up_icon
1 out of 9
circle_padding
hide_on_mobile
zoom_out_icon
logo.png

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]