Encrypt and decrypt messages using the AES encryption and Steganography
This code is roughly a 130 lines Python script. (excluding the messy ui code that creates a graphical user interface (GUI) using the tkinter library)
The script allows the user to encrypt and decrypt a message using the AES encryption algorithm from the Cryptodome library and embed the encrypted message into an image and extract it from the image. It can generate a random key, which is displayed as a QR code for savekeeping. decrypted messages can be copied to the clipboard with a click of a button.
The required packages for the script are:
- tkinter
- Cryptodome
- qrcode
- Pillow
- piexif
These packages are listed in the requirements.txt
file, which can be installed using pip as shown below.
To install and run the application, Clone the repository to your local machine and Install the required packages using pip:
git clone https://github.com/your-username/StealthCrypt.git
cd StealthCrypt
pip install -r requirements.txt
To use the application, follow these steps:
- Run the script using the command
python StealthCrypt.py
. - Enter a key in the key entry field or generate a random key using the "Generate random key" button.
- Enter a message in the message entry field.
- Click the "Encrypt" button to encrypt the message using the AES encryption algorithm to a txtfile, To embed the encrypted message into an image, click the "Embed in image" button and select an image file.
- To extract the encrypted message from an txt file click the decrypt, To extract the encrypted message from an image, click the "Extract from image" button and select an image file. The encrypted message will be displayed in the decrypted message frame.
- The decrypted message will be displayed in the decrypted message frame, To copy the decrypted message to the clipboard, click the "Copy to clipboard" button.
-
The necessary libraries are imported at the beginning of the script.
-
The
generate_random_key
function generates a random 16-byte key and displays it in the key entry field. It also generates a QR code for the key using thegenerate_qr_code
function. -
The
generate_qr_code
function generates a QR code for the given key string. It checks if the length of the key is valid (16, 24, or 32 bytes) and then creates a QR code image using the qrcode library. The image is then displayed in the QR code frame. -
The
encrypt_message
function encrypts the message entered by the user using the AES encryption algorithm. It checks if the length of the key is valid and then creates a new AES cipher object with the key and a random nonce. The message is then encrypted using the cipher object and the resulting cipher text is returned. If thesave_to_file
parameter is set to True, the encrypted message is saved to a file using thefiledialog
library. -
The
embed_in_image
function embeds the encrypted message into an image selected by the user using thefiledialog
library. It first checks if the image is large enough to contain the data and then modifies the least significant bit of each pixel in the image to contain a bit of the data. The modified image is then saved to a file and tries to include it's original meta-data. -
The
decrypt_message
function decrypts an encrypted message that has been saved to a file using thefiledialog
library. It checks if the length of the key is valid and then creates a new AES cipher object with the key and the nonce from the encrypted message. The cipher text is then decrypted using the cipher object and the resulting plain text is displayed in the decrypted message frame. -
The
extract_from_image
function extracts an encrypted message from an image selected by the user using thefiledialog
library. It reads the least significant bit of each pixel in the image to retrieve the data and then decrypts the message using thedecrypt_message
function. The resulting plain text is displayed in the decrypted message frame. -
The
copy_to_clipboard
function copies the decrypted message to the clipboard using theclipboard_append
method of the root window. -
The
on_key_release
andupdate_qr_code
functions are used to update the QR code displayed in the QR code frame whenever the user types a new key in the key entry field. -
The main GUI is created using the tkinter library. The GUI consists of several frames, including a key frame, a message frame, a decrypted message frame, a QR code frame, and an encryption/decryption frame. The encryption/decryption frame contains buttons for encrypting and decrypting messages, as well as buttons for embedding and extracting messages from images. The GUI is displayed using the
mainloop
method of the root window.
Caution
This application is provided "as is" without warranty of any kind, either express or implied. The developer of this application shall not be held liable for any damages arising from the use of this application, including but not limited to data loss, system crashes, or security breaches.
The user is responsible for ensuring the security of their encryption keys and any data encrypted using this application. The developer of this application shall not be held responsible for any unauthorized access to encrypted data.
The user is responsible for complying with all applicable laws and regulations when using this application. The developer of this application shall not be held responsible for any illegal or unethical use of this application.
By using this application, the user agrees to these terms and assumes all risks associated with its use.