Skip to main content

A secure CLI tool for encrypting, decrypting, shredding, and rotating secrets files using strong symmetric encryption.

Project description

ENVLock

codecov PyPI version Python versions License

A secure CLI tool for encrypting, decrypting, shredding, and rotating secrets files (e.g., .env) using strong symmetric encryption (Fernet/AES).

Features

  • Encrypt (lock) and decrypt (unlock) files with a 256-bit key
  • Key can be provided as hex, base64, or via the ENVLOCK_ENCRYPTION_KEY environment variable
  • Secure file shredding (overwriting and deleting original file)
  • Key rotation (renew) for re-encrypting with a new key
  • Short and long CLI options for all commands

Installation

Requires Python 3.8+ and the cryptography and click packages:

pip install cryptography click

Usage

Lock a file (encrypt)

python main.py lock [-f FILE] [-k KEY] [-h] [-s]
  • -f, --file : File to lock (default: .env)
  • -k, --key : Encryption key (hex or base64). If omitted, uses ENVLOCK_ENCRYPTION_KEY or generates a new key.
  • -h, --hide-key : Hide generated key output (default: show)
  • -s, --shred : Securely delete original file after locking

Example:

python main.py lock -f .env -s

Unlock a file (decrypt)

python main.py unlock [-f FILE] -k KEY
  • -f, --file : File to unlock (default: .env.locked)
  • -k, --key : Encryption key (hex or base64, required)

Example:

python main.py unlock -f .env.locked -k <key>

Renew (rotate) encryption key

python main.py renew [-f FILE] --old-key OLDKEY [--new-key NEWKEY] [-h]
  • -f, --file : File to renew (default: .env.locked)
  • --old-key : Current encryption key (hex or base64, required)
  • --new-key : New encryption key (hex or base64, optional; if omitted, a new key is generated)
  • -h, --hide-key : Hide generated new key output (default: show)

Example:

python main.py renew --old-key <oldkey>

Key Management

  • Keys are 32 bytes (64 hex chars or 32 bytes base64)
  • Store keys securely (never in your repo)
  • You can use the ENVLOCK_ENCRYPTION_KEY environment variable for automation

Security Notes

  • The encrypted file can be public; only the key must remain secret
  • Never print or log the key in CI/CD logs
  • Use secure deletion (--shred) for sensitive files
  • Rotate keys regularly and after any suspected compromise

Shell Completion

envlock supports shell completion for bash, zsh, and fish. To enable it, run:

eval "$(_ENVLOCK_COMPLETE=source_bash envlock)"  # for bash
eval "$(_ENVLOCK_COMPLETE=source_zsh envlock)"   # for zsh
eval "$(_ENVLOCK_COMPLETE=source_fish envlock)"  # for fish

Add the appropriate line to your shell profile to enable completion permanently.

Alternative Installation Methods

Homebrew (macOS/Linux)

You can create a Homebrew formula for envlock or use pipx:

pipx install envlock

Windows

Install with pip or pipx:

pip install envlock
# or
pipx install envlock

Troubleshooting

  • Upload to PyPI/TestPyPI fails with 400 Bad Request:
    • Ensure your version is unique and not already uploaded.
    • Check your pyproject.toml for required fields.
    • Delete the dist/ directory before building.
  • Key errors:
    • Make sure your key is 32 bytes (64 hex chars or 32 bytes base64).
    • If using ENVLOCK_ENCRYPTION_KEY, ensure it is set in your environment.
  • Permission errors:
    • Run the CLI with appropriate permissions for file access.

FAQ

Q: Can I use envlock for files other than .env? A: Yes, you can lock/unlock any file by specifying the -f option.

Q: Is the encrypted file safe to store in version control? A: Yes, as long as you keep the key secret.

Q: How do I rotate my encryption key? A: Use the renew command with --old-key and optionally --new-key.

Q: How do I securely delete the original file? A: Use the --shred option with the lock command.

License

MIT

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

envlock-0.1.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

envlock-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file envlock-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for envlock-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8a1cf5305890d4ee44a1008b34f3c36d4fdd4221d7b5d7ce0f607c0e151c9297
MD5 c782929b1df8fcb1f1c662923dc3ef7c
BLAKE2b-256 cb37aac233f607ae475da2de89e3108a2c023a85f0f1c1187990fed017eec152

See more details on using hashes here.

Provenance

The following attestation bundles were made for envlock-0.1.0.tar.gz:

Publisher: publish.yml on nikhiljohn10/envlock

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

File details

Details for the file envlock-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for envlock-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eafeda37d89a6dac0509af7f6502771ca26d214d1984ad2036ad95375f0f2b8c
MD5 fbd261c10c00da22b4ca4af9705bb7f3
BLAKE2b-256 55b0107c69e2777387958080f70151819f5cff7bb048a191718fc34e4d49de2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for envlock-0.1.0-py3-none-any.whl:

Publisher: publish.yml on nikhiljohn10/envlock

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