Image Encryption Explanation
Image Encryption Explanation
This code is a Java Swing-based GUI application for performing image encryption and
decryption using the AES (Advanced Encryption Standard) algorithm.
It allows users to upload an image, encrypt it, and decrypt it. Below is an in-depth
explanation of the entire code.
Features
1. Image Upload: Users can select an image file from their local system.
2. Image Encryption: Converts the image into a byte array, encrypts it using AES encryption,
and displays a scrambled version of the image.
3. Image Decryption: Decrypts the encrypted byte array and restores the original image.
Import Statements
Class Declaration
This class extends JFrame to provide a GUI window and implements ActionListener to
handle button click events.
Key Sections of the Code
1. Constructor (ImageEncryptionApplet)
The constructor initializes the GUI layout, adds components like buttons and labels, and sets
up the application window.
It uses GridBagLayout for flexible arrangement of components.
Buttons for 'Upload Image,' 'Encrypt,' and 'Decrypt' are created using a helper method
createCustomButton(), which styles them consistently.
These buttons are added to the top row of the window.
3. Image Labels
Labels for displaying uploaded, encrypted, and decrypted images are created and styled
using the helper method createCustomLabel().
These are added to the second row of the layout.
Encryption:
- A 128-bit AES key is generated using KeyGenerator.
- The image is converted to a byte array and encrypted using Cipher in ENCRYPT_MODE.
Decryption:
- The encrypted byte array is decrypted using Cipher in DECRYPT_MODE.
- The decrypted byte array is converted back into a BufferedImage.
6. Utility Methods
7. Application Execution