Skip to content
darkvoid97Public

About

A command-line tool that encrypts files into PNG images using symmetric encryption and restores them to their original format. Available as a standalone executable. Featuring integrity verification, automatic file-type detection, and support for 70 cipher/mode combinations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

DarKrypt

DarKrypt Icon

Python discord.py License: MIT

DarKrypt is a command-line utility tool that encrypts any file into a square RGB PNG image and restores it back to its original format and extension. It combines symmetric encryption, memory-hard password key derivation (Argon2id), HMAC-SHA256 authentication, automatic file-type detection, and PNG tEXt metadata storage.

Table of Contents

Features

  • File-to-PNG Encryption: Packs raw encrypted ciphertext directly into the RGB channels of a square PNG image.
  • Argon2id Key Derivation: Derives encryption keys, IVs, and MAC keys from user-supplied passwords (supporting letters, numbers, and symbols) with a unique 16-byte random salt per file.
  • Default Password Fallback: Allows quick encoding/decoding without passing -p/--password by falling back to a built-in default password ("DarKrypt").
  • Tamper & Wrong-Password Detection: Authenticates both the metadata header and ciphertext using HMAC-SHA256 before writing any decrypted data to disk.
  • Automatic File Type Detection & Restoration: Detects the original file extension (via filename suffix, binary magic signatures, RIFF headers, MIME types, or UTF-8 text heuristics), encodes it into the PNG metadata, and automatically restores it upon decryption.
  • 70 Cipher/Mode Combinations: Supports AES, Camellia, SEED, SM4, CAST5, Blowfish, IDEA, TripleDES, and ARC4 across ECB, CBC, CTR, OFB, CFB, and stream modes.
  • Standalone Binary Support: Easily compiles into a single portable executable via PyInstaller with no Python runtime required on target machines.

Standalone Executable

DarKrypt is available for download as a single portable executable file, so you don't have to require anything at all, you can just run it as a CLI program without any installation required. In this case, you can skip the Requirements & Installation part and check Usage.

Requirements & Installation

Install the required packages via pip:

pip install "cryptography>=42.0.0" Pillow

Building a Standalone Executable (PyInstaller)

You can package darkrypt.py and encryption.py into a single standalone executable using PyInstaller so the CLI can be distributed and run on systems without Python installed.

1. Install PyInstaller

pip install pyinstaller

2. Compile to a Single Executable

Run the following command from the project root directory (where both darkrypt.py and encryption.py are located):

pyinstaller --onefile --name darkrypt --collect-all cryptography darkrypt.py
  • --onefile: Bundles Python, darkrypt.py, encryption.py, Pillow, and cryptography into a single executable file.
  • --name darkrypt: Names the resulting binary darkrypt.exe (Windows) or darkrypt (Linux/macOS).
  • --collect-all cryptography: Ensures all dynamic CFFI/Rust backend bindings and submodules required by cryptography (including Argon2id and symmetric ciphers) are included inside the bundle.

3. Locate and Run the Executable

Once the build finishes, your standalone binary will be inside the dist/ folder:

  • Windows: dist\darkrypt.exe
  • Linux / macOS: dist/darkrypt

You can run it directly from anywhere (or move it into a directory on your system PATH):

# Windows
.\dist\darkrypt.exe encrypt -i secret.pdf -p "MyPassword123!"
.\dist\darkrypt.exe decrypt -i drk_enc.png -p "MyPassword123!"

# Linux / macOS
./dist/darkrypt encrypt -i secret.pdf -p 'MyPassword123!'
./dist/darkrypt decrypt -i drk_enc.png -p 'MyPassword123!'

(Note: Build artifacts generated in build/ and darkrypt.spec can be safely deleted.)

Usage

(The commands examples below use the compiled executable binary, if you want to use the Python files replace darkrypt with python darkrypt.py in the commands below.)

Encrypting a File

darkrypt encrypt -i <INPUT_FILE> [-o <OUTPUT_PNG>] [-p <PASSWORD>] [-a <ALGORITHM>]
Flag Long Flag Required Default Description
-i --input Yes — Path to the input file to encrypt.
-o --output No drk_enc.png Output PNG path. Automatically appends .png if omitted.
-p --password No "DarKrypt" Password used to derive cryptographic keys via Argon2id.
-a --algo No aes-256-cbc Cipher algorithm and mode to use.

Examples

# Encrypt using default password, default algorithm (aes-256-cbc), and default output (drk_enc.png)
darkrypt encrypt -i secret.pdf

# Encrypt with a custom password and output name (.png is added automatically)
darkrypt encrypt -i report.docx -o vault_report -p 'My$tr0ng!P@ssw0rd'

# Encrypt using a specific algorithm (e.g., Camellia-256 in CTR mode)
darkrypt encrypt -i archive.zip -o encoded.png -p 'CorrectHorseBatteryStaple!' -a camellia-256-ctr

Tip: Wrap passwords containing shell-special characters ($, !, &, *, spaces) in single quotes ('...') on Linux/macOS or double quotes ("...") on Windows PowerShell.

Decrypting an Image

darkrypt decrypt -i <ENCRYPTED_PNG> [-o <OUTPUT_FILE>] [-p <PASSWORD>]
Flag Long Flag Required Default Description
-i --input Yes — Path to the DarKrypt-encoded PNG image.
-o --output No drk_dec.<ext> Output file path. Any extension given is replaced by the original detected extension stored in metadata.
-p --password No "DarKrypt" Password used during encryption.

Examples

# Decrypt using default password -> writes drk_dec.<original_ext>
darkrypt decrypt -i drk_enc.png

# Decrypt with a custom password and output path -> writes restored_report.docx
darkrypt decrypt -i vault_report.png -o restored_report.txt -p 'My$tr0ng!P@ssw0rd'

Listing Supported Algorithms

To view all 70 supported cipher and mode combinations without cluttering encrypt --help:

darkrypt --list-algos

How It Works Under the Hood

1. Key Derivation (Argon2id)

When encrypting or decrypting, the program generates a single contiguous block of key material using Argon2id with a random 16-byte (SALT_BYTES = 16) salt:

  • Iterations (time_cost): 3
  • Parallelism (lanes): 4
  • Memory Cost: 65,536 KiB (64 MiB)

The derived output length equals key_len + iv_len + 32 bytes and is sliced into three independent secrets:

  1. key: key_size // 8 bytes for the symmetric cipher.
  2. iv: block_size // 8 bytes for block modes requiring an initialization vector/counter (CBC, CTR, OFB, CFB), or empty (b"") for ECB and ARC4.
  3. auth_key: 32 bytes (AUTH_KEY_BYTES) dedicated exclusively to HMAC authentication.

If -p/--password is omitted (None), it falls back to DEFAULT_PASSWORD ("DarKrypt"). Passing an explicitly empty string (-p "") raises an error, so the password can't be empty if specified.

2. Symmetric Encryption & Padding

  • Block Modes (ECB, CBC): Plaintext is padded via pad_bytes() using null bytes (\x00) up to the next block boundary (bs - (len(data) % bs)). Exact byte recovery is guaranteed because the original plaintext byte length (orig_len) is recorded in metadata and sliced (decrypted[:orig_len]) after decryption.
  • Stream / Streaming Block Modes (CTR, OFB, CFB, NONE): Encrypted directly without padding.

3. Integrity & Password Verification (HMAC-SHA256)

Before encryption finishes, the program computes an HMAC-SHA256 tag over the metadata header and the ciphertext:

HMAC-SHA256(auth_key, header_without_tag.encode("utf-8") + b"|" + encrypted_bytes)

During decryption:

  1. The key material is re-derived from the supplied password and the salt stored in metadata.
  2. The expected HMAC tag is recomputed over the metadata header and pixel ciphertext.
  3. The program verifies the tag in constant time before decrypting or writing any file to disk. If the password is wrong or the image/metadata was altered, execution aborts with an error.

4. Pixel Packing & PNG Metadata Format

  1. Square RGB Grid Calculation:

    • Each pixel stores 3 bytes (R, G, B).

    • Total pixels needed: $\lceil \text{len}(\text{encrypted}) / 3 \rceil$.

    • Square side length: $\max\left(1, \left\lceil \sqrt{\text{pixel\_count}} \right\rceil\right)$

    • Remaining bytes up to $\text{size} \times \text{size} \times 3$ are padded with \x00.

  2. PNG Metadata (tEXt chunk):

    • Stored under the chunk key "drk" as 7 comma-separated fields:

      pwd,<algo>,<salt_hex>,<encoded_ext>,<orig_len>,<enc_len>,<tag_hex>
      
    • encoded_ext is the URL-safe Base64 encoding of the detected file extension (e.g., .pdf $\rightarrow$ LnBkZg==), ensuring punctuation or empty extensions never break comma splitting.

5. File Type Detection & Output Path Resolution

  • Input Extension Detection:

    1. Checks if the input file already has an extension.
    2. Otherwise it inspects magic byte headers for common binary formats (.png, .jpg, .gif, .pdf, .zip, .gz, .rar, .7z, .mp3, .ogg, .flac, .mp4, .mkv, .sqlite, .exe, .elf, plus RIFF containers .wav, .avi, .webp).
    3. Falls back to mimetypes.guess_type(), and finally checks if the first 4,096 bytes are valid UTF-8 to assign .txt.
  • Output Path Rules:

    • Encrypt: Defaults to drk_enc.png if -o is omitted; appends .png if the provided path does not end with .png.
    • Decrypt: Defaults to drk_dec if -o is omitted; replaces any extension on -o with the original extension decoded from metadata.

Supported Ciphers & Modes

Defined in encryption.py (Encryption.methods):

Cipher Family Key Sizes (bits) Supported Modes
AES (aes-*) 128, 192, 256 ecb, cbc, ctr, ofb, cfb
Camellia (camellia-*) 128, 192, 256 ecb, cbc, ctr, ofb, cfb
SM4 (sm4-*) 128 ecb, cbc, ctr, ofb, cfb
SEED (seed-*) 128 ecb, cbc, ofb, cfb
CAST5 (cast5-*) 128 ecb, cbc, ofb, cfb
Blowfish (bf-*) 128 ecb, cbc, ofb, cfb
IDEA (idea-*) 128 ecb, cbc, ofb, cfb
TripleDES (des3-*) 64, 128, 192 ecb, cbc, ofb, cfb
ARC4 (rc4-*) 40, 56, 64, 80, 128, 192, 256 Stream (Mode.NONE)

Security Considerations

  • Choose Modern Ciphers & Modes: Prefer aes-256-cbc, aes-256-ctr, or camellia-256-ctr (all protected by DarKrypt's Encrypt-then-MAC HMAC-SHA256 layer). Legacy algorithms like rc4-*, des3-64-*, and ecb mode are included for completeness/experimentation and should not be used for sensitive data.
  • Default Password: Encrypting without -p uses the public fallback password ("DarKrypt"), meaning anyone with DarKrypt can decrypt the file. Always supply a strong, unique password with -p for confidential files.
  • Metadata Preservation: Because DarKrypt stores parameters in the PNG tEXt chunk (drk), re-saving or uploading the PNG to platforms that strip PNG metadata or recompress images (such as social media or messaging apps) will prevent decryption. Transfer the PNG file intact (e.g., as a raw file or inside a .zip archive).

Author & License

MIT © Giuseppe Tansella

About

A command-line tool that encrypts files into PNG images using symmetric encryption and restores them to their original format. Available as a standalone executable. Featuring integrity verification, automatic file-type detection, and support for 70 cipher/mode combinations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages