CCS354 Network Security Lab Manual (1-4)
CCS354 Network Security Lab Manual (1-4)
Aim:
Algorithm:
Program:
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.util.Scanner;
// Initialize Cipher
Cipher cipher = Cipher.getInstance("AES");
// Encrypt
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encrypted = cipher.doFinal(plainText.getBytes());
System.out.println("Encrypted Text (Base64 Encoded): " +
java.util.Base64.getEncoder().encodeToString(encrypted));
// Decrypt
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] decrypted = cipher.doFinal(encrypted);
System.out.println("Decrypted Text: " + new String(decrypted));
}
}
Output:
Result:
The implementation of AES Symmetric Key Encryption and Decryption was
successfully executed.
Ex.No.2: Implement asymmetric key algorithms and key exchange algorithms
Aim:
To implement Asymmetric Key Cryptography using the RSA algorithm and perform key
exchange for secure communication.
Algorithm:
1. Generate an RSA key pair (Public Key & Private Key).
2. Accept plaintext input from the user.
3. Encrypt the plaintext using the Public Key.
4. Display the encrypted text in Base64 encoding for readability.
5. Accept encrypted input for decryption (Base64 format).
6. Decrypt the encrypted text using the Private Key.
7. Display the original decrypted message to verify correctness.
Program:
import java.security.*;
import javax.crypto.Cipher;
import java.util.Scanner;
Result:
The implementation of Asymmetric Key Encryption and Decryption using the RSA
Algorithm was successfully executed.
Ex.No.3 Implement digital signature schemes
Aim:
To implement a Digital Signature Scheme using the RSA algorithm and SHA-256
hashing for message authentication and integrity verification.
Algorithm:
1. Generate an RSA Key Pair (Public Key & Private Key).
2. Accept a message from the user.
3. Generate a digital signature using the Private Key and SHA-256 hashing.
4. Display the generated signature in Base64 format for readability.
5. Verify the digital signature using the Public Key.
6. Test signature verification by altering the message and verifying again.
7. Display verification results, proving message integrity and authentication.
Program:
import java.security.*;
import java.util.Base64;
import java.util.Scanner;
Result:
The implementation of Digital Signature Scheme using RSA and SHA-256 was successfully
executed
Ex.No.4 Installation of Wire shark, tcpdump and observe data transferred in client-server
communication using UDP/TCP and identify the UDP/TCP datagram.
Aim:
To install and use Wireshark and tcpdump to observe network traffic and analyze
TCP/UDP datagrams in client-server communication.
Procedure:
Using Wireshark:
● Launch Wireshark:
sudo wireshark
● Select the network interface (e.g., eno1 for Ethernet).
● Start capturing packets by clicking the Start button.
● Use display filters to focus on specific traffic:
○ For TCP: tcp
○ For UDP: udp
● Observe the packets in the capture window. You can see details like source IP, destination
IP, ports, and payload.
Using tcpdump:
● Open a terminal.
● Capture TCP traffic:
sudo tcpdump -i <interface> tcp
Replace <interface> with your network interface (e.g., eno1).
● Capture UDP traffic:
sudo tcpdump -i <interface> udp
● Save the captured packets to a file for later analysis:
sudo tcpdump -i <interface> -w capture.pcap
You can open the capture.pcap file in Wireshark for detailed analysis.
1. Use Wireshark or tcpdump to capture the traffic while running the client-server
communication.
2. In Wireshark:
○ Look for packets with the protocol UDP or TCP.
○ Expand the packet details to see the headers (source port, destination port,
checksum, etc.).
○ For TCP, observe the sequence numbers, acknowledgment numbers, and flags
(SYN, ACK, FIN, etc.).
○ For UDP, the header is simpler, containing only source port, destination port,
length, and checksum.
3. In tcpdump:
○ The output will show the source and destination IPs and ports, along with the
protocol (UDP/TCP).
Step 6: Identify UDP/TCP Datagrams
● UDP Datagram:
○ Connectionless protocol.
○ No handshake or acknowledgment.
○ Smaller header (8 bytes).
● TCP Datagram:
○ Connection-oriented protocol.
○ Three-way handshake (SYN, SYN-ACK, ACK).
○ Larger header (20 bytes) with sequence numbers, acknowledgment numbers, and
flags.
Result:
The installation of Wireshark and tcpdump was successful. Network traffic was
captured, and TCP/UDP datagrams were identified and analyzed.