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.
- Features
- Standalone Executable
- Requirements & Installation
- Building a Standalone Executable (PyInstaller)
- Usage
- How It Works Under the Hood
- Supported Ciphers & Modes
- Security Considerations
- Author & License
- 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/--passwordby 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.
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.
- Python: 3.10 or higher
- Dependencies:
cryptography(>= 42.0.0forArgon2id)Pillow
Install the required packages via pip:
pip install "cryptography>=42.0.0" PillowYou 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.
pip install pyinstallerRun 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, andcryptographyinto a single executable file.--name darkrypt: Names the resulting binarydarkrypt.exe(Windows) ordarkrypt(Linux/macOS).--collect-all cryptography: Ensures all dynamic CFFI/Rust backend bindings and submodules required bycryptography(includingArgon2idand symmetric ciphers) are included inside the bundle.
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.)
(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.)
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. |
# 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-ctrTip: Wrap passwords containing shell-special characters (
$,!,&,*, spaces) in single quotes ('...') on Linux/macOS or double quotes ("...") on Windows PowerShell.
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. |
# 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'To view all 70 supported cipher and mode combinations without cluttering encrypt --help:
darkrypt --list-algosWhen 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:
key:key_size // 8bytes for the symmetric cipher.iv:block_size // 8bytes for block modes requiring an initialization vector/counter (CBC,CTR,OFB,CFB), or empty (b"") forECBandARC4.auth_key:32bytes (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.
- Block Modes (
ECB,CBC): Plaintext is padded viapad_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.
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:
- The key material is re-derived from the supplied password and the salt stored in metadata.
- The expected HMAC tag is recomputed over the metadata header and pixel ciphertext.
- 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.
-
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.
-
-
PNG Metadata (
tEXtchunk):-
Stored under the chunk key
"drk"as 7 comma-separated fields:pwd,<algo>,<salt_hex>,<encoded_ext>,<orig_len>,<enc_len>,<tag_hex> -
encoded_extis the URL-safe Base64 encoding of the detected file extension (e.g.,.pdf$\rightarrow$ LnBkZg==), ensuring punctuation or empty extensions never break comma splitting.
-
-
Input Extension Detection:
- Checks if the input file already has an extension.
- 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, plusRIFFcontainers.wav,.avi,.webp). - 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.pngif-ois omitted; appends.pngif the provided path does not end with.png. - Decrypt: Defaults to
drk_decif-ois omitted; replaces any extension on-owith the original extension decoded from metadata.
- Encrypt: Defaults to
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) |
- Choose Modern Ciphers & Modes: Prefer
aes-256-cbc,aes-256-ctr, orcamellia-256-ctr(all protected by DarKrypt's Encrypt-then-MAC HMAC-SHA256 layer). Legacy algorithms likerc4-*,des3-64-*, andecbmode are included for completeness/experimentation and should not be used for sensitive data. - Default Password: Encrypting without
-puses the public fallback password ("DarKrypt"), meaning anyone with DarKrypt can decrypt the file. Always supply a strong, unique password with-pfor confidential files. - Metadata Preservation: Because DarKrypt stores parameters in the PNG
tEXtchunk (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.ziparchive).
MIT © Giuseppe Tansella