07.07.2023 Views

Implementing-cryptography-using-python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9 ■ Mastering Cryptography Using Python 275

print("Private Key[{0} bits]: {1}\n".format(self.privateKey.bit_

length(), self.privateKey))

print("Public Key[{0} bits]: {1}\n".format(self.publicKey.bit_

length(), self.publicKey))

def displayShared (self):

"""

Display the results of the exchange.

"""

print(">>>>>>> Results:")

print("Shared Secret[{0}]: {1}\n".format(self.sharedSecret.bit_

length(), self.sharedSecret))

print("Shared Key [{0}]: {1}\n".format(len(self.key),

hexlify(self.key)))

Execution

Prior to typing your nonencrypted message, turn on Wireshark so that you can

verify the unencrypted traffic. Once you type addDH, the client sends an unencrypted

command to the server that will initiate the encryption synchronization

on both sides. Once this is triggered, the server will know that the next message

sent will be using a shared secret that was created using Diffie-Hellman key

exchange. In the real world, these certificates, as with the RSA ones too, should

be on different systems. The certificates are left on the same computer to keep the

concept easy for you to test without having to have multiple computers. With the

changes made to the client file, you should see something similar to Figure 9.9

when you execute the server file and the client file on the same machine.

Figure 9.9: Diffie-Hellman Exchange chat

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!