Answered step by step
Verified Expert Solution
Question
1 Approved Answer
exercise, we wil implement the four mechanisms required to create an encrypted socket: . 1 Symmetric key - based encryption known only to both sides
exercise, we wil implement the four mechanisms required to create an encrypted socket:
Symmetric keybased encryption known only to both sides
Common encryption key selection mechanism
Hash function
Create a MAC signature by using a public key
This lab examines building these mechanisms. Here is an illustration of the steps:
Plain Data
Encrypted Data
Encrypted Data Hash
Encrypted Data MAC
Keybased symmetric encryption
For educational reasons, we use symmetric XOR encryption rather than advanced encryption such as AES. Our encryption key wil only be bits. It is not complex to crack this key by brute force, but it illustrates the principle and si not difficult to implement.
On the transmitter side: Any two bytes about to be sent over the socket will first be XORed with the
encryption key. fI the number of bytes that need to be sent si odd, for simplicity, use only the lower bits of the encryption key.
On the receiving side: Every two bytes received from the socket si XORed with the encryption key. fI the number of bytes received is odd, use only the lower bits of the encryption key to decrypt.
Common encryption key selection
Determine the key, the shared secret value, using the DiffieHellman algorithm. The shared secret should be bits per the encryption method chosen above.
Step A: Select two prime numbers P and G smaller than maximum value of bits Step B: Each party selects a private key.
Step C: Each party calculates its own public key and sends it to the other side, using the TCP
socket opened between them. At this stage, the information passing through the socket si not yet encrypted and includes only the public keys of both parties.
Step D: Each party calculates the shared secret, a bit number as we consider taking only the remainder of the modulo division by P
Hash function
Write ahash function to your liking. The function takes the encrypted message, performs various mathematical operations, and returns a bit hash number.
Public key signature MAC
Use the RSA algorithm to generate the Message Authentication Code MAC
Use the following values: P
Q
Party Auses the private key Public key Party Buses the private key Public Key
The signature is generated as follows:
Step A: The sending party calculates the hash of the encrypted message.
Step B: The sending party calculates the value of the signature the hash to the power of the private key, modulo PQ
You can use the Python pow function, for example:
signature powhash
Step C: The sending party sends the encrypted message appended with the signature.
Step D: The receiving party uses the sending party's public key to extract the original hash, for example:
R e c e i v e d hash powsignature
Step E: The receiving party independently calculates the hash from the rest of the information sent to it
Step:F The receiving party checks fi the calculated hash is the same as Receivedhash and fi not, throws away the received message, as ti si not genuine.
Socket Communications
Stage : Establishing the encrypted channel
Exchange DiffieHellman public keys.
Exchange RSA public keys.
Stage : Encrypted communications
Messages are encrypted and signed with the MAC.
Assignment
Write a chat between a server and a client no need to work with multiple clients messages wil be transmitted ni encrypted and signed format.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started