Using the “cryptography” library we can encrypt and decrypt the bidirectional socket messages sent back and forth to the client and the server.

We use “symmetric” encryption in the example below which means the “key” to decrypt the message is shared with the client and the server.

Copy to Clipboard
Copy to Clipboard

To verify that our data is being transmitted as ciphertext (base64 encoded ciphertext), let’s load up Wireshark and packet capture the message data exchange between the server and client.

Notice below the encrypted and encoded ciphertext found during packet capture. We can use the shared (between client and server) symmetric secret key to decrypt this message manually.

Encrypted Message
Copy to Clipboard
Jesse Shelley