{"id":1620,"library":"pgpy","title":"PGPy - Pretty Good Privacy for Python","description":"PGPy is a Python library that implements Pretty Good Privacy (PGP) as described in RFC 4880. It provides capabilities for key generation, encryption, decryption, and signature management. The library is currently at version 0.6.0 and has an irregular release cadence, with major changes often accompanied by Python version requirement updates.","status":"active","version":"0.6.0","language":"en","source_language":"en","source_url":"https://github.com/SecurityInnovation/PGPy","tags":["pgp","encryption","cryptography","security","gnupg"],"install":[{"cmd":"pip install pgpy","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"PGPKey","correct":"from pgpy.pgp import PGPKey"},{"symbol":"PGPMessage","correct":"from pgpy.pgp import PGPMessage"},{"symbol":"PGPUID","correct":"from pgpy.pgp import PGPUID"},{"symbol":"constants","correct":"from pgpy import constants"}],"quickstart":{"code":"import pgpy\nfrom pgpy.constants import PubKeyAlgorithm, KeyFlags, HashAlgorithm, SymmetricKeyAlgorithm, CompressionAlgorithm\n\n# 1. Generate a new RSA PGP key\nkey = pgpy.PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 4096)\n\n# 2. Create a User ID\nuid = pgpy.PGPUID.new('Test User', comment='example', email='test@example.com')\n\n# 3. Add the User ID to the key, defining its capabilities\nkey.add_uid(uid,\n            usage={KeyFlags.Sign, KeyFlags.Encrypt},\n            hashes=[HashAlgorithm.SHA512, HashAlgorithm.SHA256],\n            ciphers=[SymmetricKeyAlgorithm.AES256, SymmetricKeyAlgorithm.AES192, SymmetricKeyAlgorithm.AES128],\n            compression=[CompressionAlgorithm.ZLIB, CompressionAlgorithm.BZ2, CompressionAlgorithm.ZIP, CompressionAlgorithm.Uncompressed])\n\n# 4. (Optional) Protect the private key with a passphrase\npassphrase = \"my_secret_passphrase\"\nkey.protect(passphrase, SymmetricKeyAlgorithm.AES256, HashAlgorithm.SHA256)\n\n# 5. Create a PGP message\nmessage_to_encrypt = pgpy.PGPMessage.new(\"This is a secret message that needs to be encrypted.\")\n\n# 6. Encrypt the message using the public key part of the generated key\nencrypted_message = key.encrypt(message_to_encrypt)\n\n# 7. Decrypt the message using the private key part\n# If the key is protected, it must be unlocked first.\nif key.is_protected:\n    with key.unlock(passphrase):\n        decrypted_message = key.decrypt(encrypted_message)\nelse:\n    decrypted_message = key.decrypt(encrypted_message)\n\nprint(f\"Original message: {message_to_encrypt.message}\")\nprint(f\"Decrypted message: {decrypted_message.message}\")\n\n# You can also export the key to an armored string\n# public_key_armor = str(key.pubkey)\n# private_key_armor = str(key) # WARNING: Handle private keys with extreme care!","lang":"python","description":"Demonstrates generating a new PGP key, adding a User ID, optionally protecting the private key with a passphrase, encrypting a simple message, and then decrypting it. This covers the fundamental use cases for PGPy."},"warnings":[{"fix":"Upgrade your Python environment to 3.5 or newer before upgrading to PGPy v0.6.0.","message":"Python 2.7 and 3.4 support was officially dropped in PGPy v0.6.0. Attempts to install or run PGPy v0.6.0+ on these Python versions will fail.","severity":"breaking","affected_versions":"<0.6.0"},{"fix":"Be aware of encoding differences. For new keys and passphrases, UTF-8 is now the standard. You may need to specify encoding or re-protect older keys.","message":"Passphrase encoding for keys changed from Latin-1 to UTF-8 in v0.5.3. This may cause compatibility issues when importing keys generated with older PGPy versions or interacting with other PGP software that expects Latin-1.","severity":"gotcha","affected_versions":"<0.5.3"},{"fix":"Upgrade PGPy to v0.5.4 or a newer version to ensure full compatibility with Python 3.8 and above.","message":"Versions of PGPy prior to v0.5.4 had compatibility breaks with Python 3.8 and newer, specifically related to importing ABCs from `collections`.","severity":"gotcha","affected_versions":"<0.5.4 running on Python >=3.8"},{"fix":"Users migrating from very old versions (pre-0.3.0) should consult the changelog for v0.3.0 and newer to adapt to the updated API for key generation, signatures, and message handling.","message":"Version 0.3.0 introduced 'semi-significant API changes' that could break existing code. This included major updates to signature generation/verification and encryption/decryption APIs.","severity":"breaking","affected_versions":"<0.3.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}