{"id":5166,"library":"crypto","title":"Simple symmetric GPG file encryption and decryption","description":"The `crypto` library provides a simple command-line interface for symmetric Gnu Privacy Guard (gpg) encryption and decryption of one or more files on Unix and Linux platforms. It acts as a wrapper around the external `gpg` command-line tool. Encryption is performed using the AES256 cipher algorithm. The current version is 1.4.1. While the GitHub repository shows some minor activity, the last PyPI release was in 2015, indicating a low maintenance or stable (feature-complete but not actively developed) status for this specific Python package.","status":"maintenance","version":"1.4.1","language":"en","source_language":"en","source_url":"https://github.com/chrissimpkins/crypto","tags":["encryption","decryption","gpg","pgp","openpgp","security","cli","symmetric","file-encryption"],"install":[{"cmd":"pip install crypto","lang":"bash","label":"Install via pip"},{"cmd":"brew install gpg # For macOS\nsudo apt-get install gnupg # For Debian/Ubuntu","lang":"bash","label":"System-level GPG installation (required)"}],"dependencies":[{"reason":"This Python library is a wrapper around the `gpg` command-line tool, which must be installed and available in the system's PATH.","package":"Gnu Privacy Guard (gpg)","optional":false}],"imports":[{"symbol":"Not typically imported programmatically","correct":"This library is primarily designed for command-line use via the `crypto` and `decrypto` executables. It does not expose a commonly used Python API for direct import and programmatic encryption/decryption within other Python code."}],"quickstart":{"code":"import subprocess\nimport os\n\n# Create a dummy file for encryption\nwith open('secret_message.txt', 'w') as f:\n    f.write('This is a highly sensitive secret!')\n\nprint('Encrypting secret_message.txt...')\n# Encrypt the file using the 'crypto' command-line tool\n# The user will be prompted for a passphrase in the terminal\nencrypt_process = subprocess.run(['crypto', 'secret_message.txt'], capture_output=True, text=True)\nprint(encrypt_process.stdout)\nif encrypt_process.stderr:\n    print('Encryption Error:', encrypt_process.stderr)\n\n# Check if the encrypted file exists (usually .gpg or .crypt extension)\nencrypted_file_exists = False\nfor f in os.listdir('.'):\n    if f.startswith('secret_message.txt.') and (f.endswith('.gpg') or f.endswith('.crypt')):\n        encrypted_file = f\n        encrypted_file_exists = True\n        break\n\nif encrypted_file_exists:\n    print(f'File encrypted to {encrypted_file}. Now attempting decryption...')\n    # Decrypt the file using the 'decrypto' command-line tool to standard output\n    # The user will be prompted for the passphrase again\n    decrypt_process = subprocess.run(['decrypto', '--stdout', encrypted_file], capture_output=True, text=True)\n    if decrypt_process.stderr:\n        print('Decryption Error:', decrypt_process.stderr)\n    else:\n        print('Decrypted Content:', decrypt_process.stdout.strip())\n\n# Clean up dummy files\nif os.path.exists('secret_message.txt'):\n    os.remove('secret_message.txt')\nif encrypted_file_exists and os.path.exists(encrypted_file):\n    os.remove(encrypted_file)\n","lang":"python","description":"This quickstart demonstrates how to use the `crypto` library via its command-line interface from within a Python script using `subprocess`. It encrypts a temporary file and then decrypts it to standard output. Note that `gpg` must be installed on your system, and the `crypto` and `decrypto` commands must be in your system's PATH. You will be prompted for a passphrase by `gpg` during execution."},"warnings":[{"fix":"Evaluate your actual cryptographic needs. If you require programmatic access to low-level crypto primitives or a modern, actively maintained library, use `cryptography` or `PyCryptodome`. If you specifically need to interact with `gpg` from Python, `python-gnupg` might be a more suitable library.","message":"This `crypto` library is a command-line wrapper around GPG for file encryption/decryption, NOT a general-purpose Python cryptography library. For robust, general-purpose cryptographic primitives (e.g., hash functions, symmetric/asymmetric encryption, TLS), consider using `cryptography` or `PyCryptodome` instead.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always verify the source and purpose of a cryptographic library. For new projects, prefer `cryptography` or `PyCryptodome` which are actively maintained and clearly distinguish themselves.","message":"The name `crypto` is ambiguous and can be easily confused with the *deprecated and insecure* `PyCrypto` library. `PyCrypto` is unmaintained and contains known security vulnerabilities. Ensure you are installing `chrissimpkins/crypto` if that is your intention, but be aware of the naming collision.","severity":"deprecated","affected_versions":"All versions"},{"fix":"Install `gpg` on your operating system (e.g., `brew install gpg` on macOS, `sudo apt-get install gnupg` on Debian/Ubuntu) and ensure it's accessible in your system's PATH.","message":"The `crypto` library requires the external `gpg` (Gnu Privacy Guard) command-line tool to be installed and configured on the operating system where it is run. It will not function without a working `gpg` installation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For critical applications, assess the risks of using an un-updated library for encryption. Consider alternatives like `cryptography` or `PyCryptodome` which have active development and regular security updates. If using `chrissimpkins/crypto`, ensure your underlying `gpg` installation is kept up-to-date independently.","message":"The last PyPI release of `crypto` (v1.4.1) was in May 2015. While the tool might be stable for its specific purpose, the lack of recent updates for a security-sensitive domain implies it may not incorporate the latest security best practices or address newly discovered vulnerabilities in its implementation or interaction with `gpg`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}