Skip to main content

Bcryptify is a modern and elegant Python library designed to simplify the use of cryptographic algorithms, while adhering to SOLID principles to ensure clean, extensible, and maintainable code.

Project description

Bcryptify

Bcryptify is a modern and elegant Python library designed to simplify the use of cryptographic algorithms, while adhering to SOLID principles to ensure clean, extensible, and maintainable code.


📦 Installation

You can install Bcryptify directly from PyPI with pip:

pip install bcryptify

Bcryptify library dependent on the cryptography library

pip install cryptography

🚀 Use

Here is a simple example of using the AesGcmCipher class to encrypt and decrypt messages or files.

import os
from Bcryptify.aes_gcm import AesGcmCipher

# 256-bit AES key (must be kept secret)
key =
b'\xcd_\x8d\xfd1E\xd4\xe3uj\xee_\x1dj\x9c\x07\xa3\x13\x95\x96\x10\xa6\xf3\rb\xc0\x08\xde\xfa\xb6\x99\xc9'

tag = b"\xcd_\x8d\xfd1E\xd4"

# Initializing the AES-GCM cipher
aes_gcm = AesGcmCipher(key)


# --- Example of file encryption/decryption ---

def read_file(filename: str) -> bytes:
    with open(filename, "rb") as f:
        return f.read()

def write_file(filename: str, data: bytes) -> None:
    with open(filename, "wb") as f:
        f.write(data)

def encrypt_file(filepath: str) -> None:
    if not os.path.isfile(filepath):
        raise FileNotFoundError(f"The file {filepath} does not exist.")
    data = read_file(filepath)
    encrypted = aes_gcm.encrypt(data, tag)
    encrypted_filepath = filepath + ".lock"
    write_file(encrypted_filepath, encrypted)
    os.remove(filepath) 
    print(f"File encrypted in {encrypted_filepath} and original file deleted.")

def decrypt_file(encrypted_filepath: str) -> None:
    if not encrypted_filepath.endswith(".lock"):
        raise ValueError("The decrypted file must have the extension '.lock'.")
    if not os.path.isfile(encrypted_filepath):
        raise FileNotFoundError(f"The file {encrypted_filepath} does not exist.")
    data = read_file(encrypted_filepath)
    decrypted = aes_gcm.decrypt(data, tag)
    original_filepath = encrypted_filepath[:-5] 
    write_file(original_filepath, decrypted)
    os.remove(encrypted_filepath)
    print(f"Decrypted file in {original_filepath} and encrypted file deleted.")

# Example of use
file_path = "l.png"

encrypt_file(file_path)
decrypt_file(file_path + ".lock")


# ----------------------------------------


# Encrypting a text message
#message = "Hello, this is a secret message.".encode('utf-8')
#encrypted_message = aes_gcm.encrypt(message, tag)
#print(f"Encrypted message : {encrypted_message}")

# Decrypting the message
#decrypted_message = aes_gcm.decrypt(encrypted_message, tag)
#print(f"Deciphered message : {decrypted_message.decode('utf-8')}")

support

  • RSA
  • AES GCM

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

bcryptify-1.1.2.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

bcryptify-1.1.2-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file bcryptify-1.1.2.tar.gz.

File metadata

  • Download URL: bcryptify-1.1.2.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for bcryptify-1.1.2.tar.gz
Algorithm Hash digest
SHA256 e0d2b0161320f6d4a3c12fd09214aa7f785c349fef5a22625b9f0eda618d8a20
MD5 1760312d8cb0d23085be4559829fc4e5
BLAKE2b-256 79577a64825e7ffca0e18fe784c4878808b581be72a676707706fcac40a9b7a4

See more details on using hashes here.

File details

Details for the file bcryptify-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: bcryptify-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for bcryptify-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7e5b0e5dad56e81465c6b695627b3dedfff0e7e1497b45a9bfa9f575fbb014f5
MD5 a80e0495af20a59fb4f75b35ca3ffad2
BLAKE2b-256 ff7c78afe0450b391333d697fd79bbabd650e113d35c3432f373b7ff8304a204

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