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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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