Skip to main content

Secure file encryption and decryption library with fluent API

Project description

PyCypher

PyCypher is a Python library based on the libraries cryptography and argon2 that provides secure encryption and decryption, plus an optional decrypt&execute feature for encrypted Python scripts. It attempts to securely wipe in-memory data and input files (on a best-effort basis, not guaranteed on all systems).

Installation

pip install PyCypherLib

Usage

# Import the PyCypher library:
from PyCypher import Cy

# KDF Selection:
# Cy()    - Default: Argon2 (recommended for maximum security)
# Cy("A") - Explicit: Argon2
# Cy("P") - Explicit: PBKDF2
# All modes support auto-detection of encrypted file formats

# Base methods for encryption and decryption operations
# using the .P() method to type the password manually
Cy().enc("file.txt").P("yourpassword")
Cy().dec("file.txt.cy").P("yourpassword")

# With the .run() method you can 'decrypt&run' an encrypted python script
Cy().run("file.py.cy").P("yourpassword")

# By default the encrypted file is saved with the .cy extension added to the input file name
Cy().dec("file.txt.cy").P("yourpassword")

# Use the .newName() method to specify the output file name 
Cy().enc("file.txt").newName("file.enc").P("yourpassword")

# Use the .delInput() method to automatically delete the input file
Cy().enc("file.txt").newName("file.cy").delInput().P("mypassword")
Cy().dec("file.cy").newName("file.txt").delInput().P("mypassword")

# Use the .toData() method to get encrypted/decrypted data instead of writing to file
encrypted_data = Cy().enc("file.txt").toData().P("yourpassword")
decrypted_data = Cy().dec("file.txt.cy").delInput().toData().P("yourpassword")

# Use the .terminalP() method to insert the password in the terminal with your own message
Cy().dec("file.enc").newName("file.txt").delInput().terminalP("Please enter password: ")

# Use the .encLines() and Lines() methods to encrypt a single string or a list of strings
# the default output file will be cyfile.cy 
Cy().encLines().Lines('yoursecretkey').P('yourpassword')
Cy().encLines().Lines(['yoursecretkey', 'yoursecrettoken']).P('yourpassword')

# Use one or more .terminalL() methods to add lines to encrypt by terminal
# and you can specify an output file name as .encLines() argument
Cy().encLines('credentials.cy')\
    .terminalL('Enter your secret key: ')\
    .terminalL('Enter your secret token: ')\
    .terminalP('Enter a password to encrypt your credentials: ')

# Use the .decLines() method to decrypt the encrypted string or strings
# it will return a string or a list of strings
key = Cy().decLines('key.cy').terminalP('Enter a password to access your secret key: ')
key,token = Cy().decLines('credentials.cy').terminalP('Enter a password to access your credentials: ')

# Use the .changeP() and .newP() methods to change the encryption password of an encrypted file
Cy().changeP('credentials.cy').newP('newpassword').P('oldpassword')

# Examples with explicit KDF selection:
Cy("A").enc("sensitive.txt").P("strongpassword")    # Force Argon2
Cy("P").enc("legacy.txt").P("oldpassword")          # Force PBKDF2

Development status

PyCypher is a work-in-progress personal project. Suggestions, feature requests, and constructive feedback are highly welcome. Feel free to open an issue or submit a pull request.

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

pycypherlib-1.4.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

pycypherlib-1.4.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pycypherlib-1.4.1.tar.gz.

File metadata

  • Download URL: pycypherlib-1.4.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pycypherlib-1.4.1.tar.gz
Algorithm Hash digest
SHA256 3d09138ac1f2793151408f8d919734319fab2d791fd592a83bfe4d6a251f3182
MD5 691bca3717cf5cd3d544ab92926769f2
BLAKE2b-256 533c3c42ccf7161f481afedaa4bb27306fb00ee74cbc439d4a5e99af00b34ea2

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycypherlib-1.4.1.tar.gz:

Publisher: publish.yml on eaannist/PyCypher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycypherlib-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: pycypherlib-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pycypherlib-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3571a5b0c84d6819c9027242017e8d268bd0a63f0ba90ffcb6c7cab332b86c44
MD5 c46ed2936a4c658261a0782d618ef1e1
BLAKE2b-256 89e46089e03c36e79388a1f15e935c2f53593b8fd5d68a25759d09413c044251

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycypherlib-1.4.1-py3-none-any.whl:

Publisher: publish.yml on eaannist/PyCypher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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