0% found this document useful (0 votes)
13 views

Image Encryption Explanation

Uploaded by

Pranav Shingne
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Image Encryption Explanation

Uploaded by

Pranav Shingne
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Detailed Explanation of Image Encryption and Decryption Code

Purpose of the Code

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

The following libraries are imported for this program:


- javax.crypto: For AES encryption and decryption.
- javax.swing: For GUI components like buttons, labels, and dialogs.
- java.awt: For layout and styling the GUI.
- java.io: For file and stream handling.
- java.awt.image.BufferedImage: To manipulate image data in memory.
- java.util.Random: For scrambling image pixels.

Class Declaration

public class ImageEncryptionApplet extends JFrame implements ActionListener

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.

2. Button Creation and Styling

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.

4. Event Handling (actionPerformed)

This method handles button clicks for:


- Uploading images using JFileChooser and displaying them on the GUI.
- Encrypting the image data using AES and displaying a scrambled version.
- Decrypting the image data and restoring the original image.

5. AES Encryption and Decryption

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

- createCustomButton(): Creates styled buttons.


- createCustomLabel(): Creates styled labels.
- getFileExtension(): Extracts the file extension from the uploaded image file.
- scrambleImage(): Simulates encryption by scrambling the pixels of an image.

7. Application Execution

The main method creates an instance of ImageEncryptionApplet, which launches the


application window and initializes the GUI.

You might also like