Skip to main content

Library to Simplify Encryption and Data Protection

Project description

alt text workflow Static Badge Python Versions Static Badge

What is litecrypt ?

Just a library I cooked up for personal use to secure some files, you probably don't need this but if you do, here's an overview:

Encryption

AES-256 CBC leveraging primitives from the cryptography library with added features supporting both fast & very computationally intensive encryption.

Database Integration

Needed some way to store encrypted files and figure out another way to associate each file with its specific encryption key, which with this setup is automatically done.

GUI

Made to obviate the need to write code.

Installation

Starting is a breeze. Just use pip:

pip install litecrypt

Encryption

from litecrypt import CryptFile, gen_key

key = gen_key()
CryptFile('dataset.csv', key).encrypt()
# Voila! Your file is now called ==> dataset.csv.crypt

The encryption process is blazingly fast by default, to make it computationally intensive

Do this
from litecrypt import CryptFile, gen_key

key = gen_key()
CryptFile('anyfile.txt',
          key=key,
          intensive_compute=True,
          iteration_rounds=10000
          ).encrypt()

Running intensive_compute with no iteration_rounds sets the rounds to 50 (minimum) by default

To decrypt simply run:

from litecrypt import CryptFile

key = 'THE_KEY_YOU_USED'
CryptFile('anyfile.txt.crypt',key=key).decrypt()

Need to protect a message? Bet:

from litecrypt import Crypt, gen_key

key = gen_key()
encrypted = Crypt('any message', key).encrypt()  # can also be a bytes message
print(encrypted)  # Check the return value

Details

Algorithm: AES-256 CBC
Layout:

+-------------+  +--------+  +------------+  +-------------+  +-------------+  +------------------+
|    HMAC     | →|   IV   | →|   Salt     | →|  Pepper     | →| Iterations  | →|     KDF ID     |  →
+-------------+  +--------+  +------------+  +-------------+  +-------------+  +------------------+
                              +------------------+
                              |   Ciphertext    ...
                              +------------------+

The main key which is a 32-byte random hex string is provided by gen_key() function.

The higher the number of iterations, the longer it takes to encrypt/decrypt.

  • AES Key: 32-byte random value derived from the main key with the KDF, hashed with SHA256 (1 time or [50..100000] times based on the chosen number of iterations) mixed with the Salt.
  • HMAC Key: 32-byte random value derived from the main key with the KDF, hashed with SHA256 (1 time or [50..100000] times based on the chosen number of iterations) mixed with the Pepper.
  • IV: 16-byte random value.
  • Salt: 16-byte random value.
  • Pepper: 16-byte random value.
  • Iterations: 4-byte fixed value.
  • KDF ID: 4-byte fixed value used to auto-determine the Key Derivation Function (KDF) to use.
  • Ciphertext: Variable size.

Database Integration

Supported Databases

Currently, supports MySQL, PostgresSQL and SQLite.

Example Usage

from litecrypt import CryptFile, Database, gen_key, gen_ref

files = ["file", "image.png", "notes.txt"]

encryption_key = gen_key()
print(encryption_key) # check it out

# encrypt files
for file in files:
    CryptFile(file,key=encryption_key).encrypt(echo=True)
    # each one of these files ends with .crypt now

same_files_but_with_crypt_extension = ["file.crypt",
                                       "image.png.crypt",
                                       "notes.txt.crypt"]

# Create & connect to the databases (sqlite for now)
main_db = Database('xyz_main.db',echo=True)
keys_db = Database('xyz_keys.db',for_keys=True,echo=True)

# To link up the two databases generate a:
reference_value = gen_ref()
print(reference_value) # check it out

for encrypted_file_name in same_files_but_with_crypt_extension:
    with open(encrypted_file_name,'rb') as f:
        encrypted_file_binary_content = f.read()
        # Insert encrypted content and keys into the databases
        # & link'em up with a ref value
        main_db.insert(encrypted_file_name,
                       encrypted_file_binary_content,
                       ref=reference_value)
        keys_db.insert(encrypted_file_name,
                       encryption_key,
                       ref=reference_value)

Confused huh? check the Docs.

Or, Simplify with the GUI

alt text

Here's how it works

https://github.com/AshGw/litecrypt/assets/126174609/190b6ab8-3f8a-4656-9525-dbaf5e56db5e

Documentation

Check out the Docs.

License

Litecrypt is open-source project & licensed under the MIT License.

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

litecrypt-0.2.1.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

litecrypt-0.2.1-py3-none-any.whl (41.3 kB view details)

Uploaded Python 3

File details

Details for the file litecrypt-0.2.1.tar.gz.

File metadata

  • Download URL: litecrypt-0.2.1.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.17

File hashes

Hashes for litecrypt-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4a98448a9974b5dde2febc21a378e6a5d345b944754b551b72df2994bcb1041d
MD5 92d67e53fd865d7829eb378357eb9a62
BLAKE2b-256 dc37a616e65c78cb43c1a2b48abc1484d5212c7e9d15c7fe0df7ac0069748b6b

See more details on using hashes here.

File details

Details for the file litecrypt-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: litecrypt-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 41.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.17

File hashes

Hashes for litecrypt-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cfb73629bfce99b85eeeebc947866ab27d9c39aaa6167213f3c5881f8cbc9acd
MD5 db80226effc5072b9f7d987ca89464ae
BLAKE2b-256 c97a6eb78ffa01cea58f3caed49a17fe9310944c512f42dbf49590909229dad0

See more details on using hashes here.

Supported by

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