Skip to main content

AES-256 CBC file encryption library with support for individual files and directory batch operations.

Project description

brachinus

AES-256 CBC file encryption library with support for individual files and directory batch operations.

Supports single-file and directory batch operations + command-line usage

Brachinus is a simple, secure, and feature-rich AES-256 encryption library for Python.
It supports password-based key derivation, random binary keys, file/directory encryption, and includes a built-in CLI interface.


Features

  • AES-256 encryption (CBC mode)
  • PBKDF2 key derivation (100k iterations)
  • Automatic IV generation
  • Salt + IV metadata stored in output file
  • File and directory encryption/decryption
  • Optional extension filtering
  • Key saving/loading utilities
  • Built-in command-line interface (CLI)

Installation

Install:

pip install brachinus

Or install from source:

git clone https://github.com/JuanBindez/brachinus
cd brachinus
pip install .

Usage (Python API)

Encrypt a file with a password

from brachinus import encrypt_file_with_password

encrypt_file_with_password("example.txt", "mypassword")

Creates:

example.txt.enc

Decrypt a file

from brachinus import decrypt_file_with_password

decrypt_file_with_password("example.txt.enc", "mypassword")

Using the AES256 Class Directly

With a password

from brachinus import AES256

aes = AES256(password="mypassword")
aes.encrypt_file("data.pdf")
aes.decrypt_file("data.pdf.enc")

With a random binary key

aes = AES256()  # generates a new random key
print(aes.key)

Key save/load

aes.save_key("aes.key")
loaded = AES256.load_from_keyfile("aes.key")

Directory Encryption

Encrypt all files

aes.encrypt_directory("myfolder")

Produces:

myfolder_encrypted/

Encrypt only specific extensions

aes.encrypt_directory("photos", extensions=[".jpg", ".png"])

Directory Decryption

aes.decrypt_directory("myfolder_encrypted")

Creates:

myfolder_encrypted_decrypted/

Key Information

info = aes.get_key_info()
print(info)

Example:

{
    "key": "...",
    "key_hex": "a4f5...",
    "salt": "...",
    "salt_hex": "d2ab...",
    "key_type": "password-derived"
}

Internal Encrypted File Format

[4 bytes salt_length] [salt (if present)] [16-byte IV] [encrypted_data]
  • Salt only stored for password-derived keys
  • IV always present
  • Ensures reproducible decryption

Command Line Interface (CLI)

Brachinus includes a terminal command: brachinus

After installation you can run:

brachinus --help

CLI Commands

Encrypt a file

brachinus encrypt-file input.txt

Encrypt a file with password

brachinus encrypt-file input.txt --password "mypassword"

Decrypt a file

brachinus decrypt-file input.txt.enc --password "mypassword"

Encrypt a directory

brachinus encrypt-dir myfolder --password "mypassword"

Decrypt a directory

brachinus decrypt-dir myfolder_encrypted --password "mypassword"

Use a keyfile instead of password

brachinus encrypt-file document.pdf --keyfile aes.key

Security Notes

⚠️ Use strong passwords
⚠️ Never reuse password + salt manually
⚠️ Keep .key files secure
⚠️ Lost passwords or keys cannot be recovered


Project details


Download files

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

Source Distribution

brachinus-1.0.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

brachinus-1.0.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file brachinus-1.0.0.tar.gz.

File metadata

  • Download URL: brachinus-1.0.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for brachinus-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0c63b3885919a833f73ccef68933c390dec1115a3956a29b69d31e4b1717278d
MD5 2ee2f5d1cc2410a40dc90d40689f86b6
BLAKE2b-256 98c093abfe9cf91287fcb95f3e6f6d123cd22e17c209a86ee894e4830d7ad466

See more details on using hashes here.

File details

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

File metadata

  • Download URL: brachinus-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for brachinus-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4e0374e366d68ef5e0bdaa39c87628066c56d1ae0152bc10a78e590ac7398d7
MD5 359bc64062a2905cd89f385a9a185166
BLAKE2b-256 77d4514c3b902e42a795eeecb30bbc1a3876dfdda19b80edf359be4b08794d80

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