Engineering ProjectsBsc-ITDiplomaIT ProjectsMsc-IT Projects

Image Encryption Using AES Algorithm Project

Introduction

In today’s digital age, the secure transmission and storage of digital images have become paramount. This is particularly true for sectors like healthcare, military, and multimedia systems. This article explores the use of the Advanced Encryption Standard (AES) algorithm for image encryption and decryption, offering a secure solution for protecting digital images against unauthorized access.

Why AES for Image Encryption?

AES stands out for its robustness and security features, making it a preferred choice over other encryption methods like DES (Data Encryption Standard) and Triple DES. AES uses a key size of 192 bits, enhancing the security of the encryption and decryption process.

How AES Works for Image Encryption

The AES algorithm encrypts the digital image by converting it into a series of blocks and then applying multiple rounds of substitution, permutation, and mixing functions. The key, known only to the sender and receiver, is used to encrypt and decrypt the image, ensuring that only authorized parties can view it.

Advantages of Using AES for Image Encryption

  • Enhanced Security: AES offers a higher level of security compared to DES and Triple DES.
  • Confidentiality: Only the sender and receiver, who have the key, can view the encrypted image.
  • Robust Key Size: The 192-bit key size makes the encryption and decryption process highly secure.

Disadvantages

  • Increased File Size: The encrypted image file size becomes large, which can be a drawback in some applications.
  • Potential for Suspicion: The large file size may raise suspicions that the file contains critical information.

Applications

AES-based image encryption is widely used in:

  • Internet communication
  • Medical imaging systems
  • Military applications
  • Multimedia systems

Conclusion

Image encryption using the AES algorithm offers a reliable and secure method for the protection of digital images. While it does have some drawbacks, such as increased file size, the benefits far outweigh the disadvantages, making it a go-to choice for secure image encryption and decryption.

Sample Code

First, install the required packages:

pip install Pillow
pip install pycryptodome
from PIL import Image
from Crypto.Cipher import AES
import os

# Function to pad data to be 16-byte aligned
def pad(data):
    return data + b"\x00" * (16 - len(data) % 16)

# Function to encrypt image
def encrypt_image(image_path, key_path, encrypted_path):
    # Open image and convert to byte array
    img = Image.open(image_path)
    img_byte_arr = img.tobytes()

    # Pad image byte array to be 16-byte aligned
    img_byte_arr = pad(img_byte_arr)

    # Create AES cipher object
    key = open(key_path, "rb").read()
    cipher = AES.new(key, AES.MODE_ECB)

    # Encrypt image byte array
    encrypted_img_byte_arr = cipher.encrypt(img_byte_arr)

    # Save encrypted image
    encrypted_img = Image.frombytes(img.mode, img.size, encrypted_img_byte_arr)
    encrypted_img.save(encrypted_path)

# Function to decrypt image
def decrypt_image(encrypted_path, key_path, decrypted_path):
    # Open encrypted image and convert to byte array
    encrypted_img = Image.open(encrypted_path)
    encrypted_img_byte_arr = encrypted_img.tobytes()

    # Create AES cipher object
    key = open(key_path, "rb").read()
    cipher = AES.new(key, AES.MODE_ECB)

    # Decrypt image byte array
    decrypted_img_byte_arr = cipher.decrypt(encrypted_img_byte_arr)

    # Save decrypted image
    decrypted_img = Image.frombytes(encrypted_img.mode, encrypted_img.size, decrypted_img_byte_arr)
    decrypted_img.save(decrypted_path)

# Generate a random 192-bit key and save it
key = os.urandom(24)
with open("key.key", "wb") as key_file:
    key_file.write(key)

# Paths
image_path = "original_image.jpg"  # Replace with your image path
key_path = "key.key"
encrypted_path = "encrypted_image.jpg"
decrypted_path = "decrypted_image.jpg"

# Encrypt and decrypt image
encrypt_image(image_path, key_path, encrypted_path)
decrypt_image(encrypted_path, key_path, decrypted_path)

Replace original_image.jpg with the path to the image you want to encrypt. This code will save the encrypted image as encrypted_image.jpg and the decrypted image as decrypted_image.jpg.

Click to rate this post!
[Total: 0 Average: 0]

Download Image Encryption Using AES Algorithm Project PDF


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button