Skip to main content

it is a tool for encrypting images

Project description

# Image Vault

Image Vault is a tool for encrypting and decrypting image files. It allows you to securely split images into multiple encrypted parts and then reassemble them. The project leverages AES encryption to ensure the security of your image files.

## Features

- Encrypt images by splitting them into multiple parts.
- Decrypt images and reassemble them from encrypted parts.
- Supports customizable number of parts for splitting.
- Uses AES encryption for secure data handling.

## Requirements

- Python 3.x
- Required Python packages:
  - `cryptography`
  - `pillow`
  - `click`

You can install the required packages using pip:

```bash
pip install cryptography pillow click

Usage

The main script provides a command-line interface with options for encryption and decryption.

Encrypting a Folder of Images

To encrypt a folder of images, use the --encrypt flag. You can specify the input path, output path, key, and number of parts for splitting:

python script.py --encrypt --input_path ./path/to/images --output_path ./path/to/output --key your_key --parts 4

Decrypting a Folder of Encrypted Images

To decrypt a folder of encrypted images, use the --decrypt flag. You only need to specify the input path and the key:

python script.py --decrypt --input_path ./path/to/encrypted --key your_key

Command Line Options

  • --encrypt: Use this flag for encryption.
  • --decrypt: Use this flag for decryption.
  • --input_path: Path to the input directory. Default is ./.
  • --output_path: Path to the output directory. Default is ./op.
  • --key: Encryption/Decryption key. Default is 1234.
  • --parts: Number of parts to split the file into for encryption. Default is 1.

Example

Encrypting an image folder:

python script.py --encrypt --input_path ./test_images --output_path ./encrypted_images --key mysecretkey --parts 4

Decrypting an image folder:

python script.py --decrypt --input_path ./encrypted_images --key mysecretkey

Implementation Details

Key Generation

A key is generated from a seed token using SHA-256 hashing:

def key_gen(seed):
    seed = bytes(seed, "utf-8")
    seed_hash = hashlib.sha256()
    seed_hash.update(seed)
    return seed_hash.hexdigest()

Encryption

Images are split into parts, each part is padded, and then encrypted using AES in CBC mode:

def encrypt_file(f_name, file_number, input_file, seed_token):
    key = seed_token.ljust(32)[:32].encode('utf-8')
    iv = os.urandom(16)
    cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
    encryptor = cipher.encryptor()
    data = input_file
    padder = padding.PKCS7(algorithms.AES.block_size).padder()
    padded_data = padder.update(data) + padder.finalize()
    encrypted_data = encryptor.update(padded_data) + encryptor.finalize()
    hex_data = binascii.hexlify(iv + encrypted_data).decode('utf-8')
    with open(f'{f_name}{file_number}', 'w') as output_file:
        output_file.write(hex_data)
    print(f"Encrypted data written to {f_name}{file_number}")

Decryption

The encrypted parts are read, decrypted, and reassembled into the original image:

def decrypt_file(input_file, seed_token):
    key = seed_token.ljust(32)[:32].encode('utf-8')
    hex_data = input_file
    encrypted_data_with_iv = binascii.unhexlify(hex_data)
    iv = encrypted_data_with_iv[:16]
    encrypted_data = encrypted_data_with_iv[16:]
    cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
    decryptor = cipher.decryptor()
    padded_data = decryptor.update(encrypted_data) + decryptor.finalize()
    unpadder = padding.PKCS7(algorithms.AES.block_size).unpadder()
    data = unpadder.update(padded_data) + unpadder.finalize()
    print("Decrypted data")
    return data

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

image_vault-1.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file image_vault-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: image_vault-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for image_vault-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4aee5e977869c65c638a4d26156dba0b9639d38deb609e1ac7878c329158d3b
MD5 a9867a5550f04795456bcbe808b0c14c
BLAKE2b-256 d1f372ff56e4e5a269a373c9e4788df96495f104f89ceee7fc668daa33416b9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page