phPGP
phpgp is a command-line utility designed for secure storage and usage of PGP keys on external drives (such as USB flash drives). The project provides a server component to handle cryptographic operations (sign, encrypt, decrypt) in memory, ensuring private keys do not remain on the host machine.
This README covers installation, usage, configuration, and other important details for working with phpgp.
Table of Contents
Features
- Secure PGP key storage on external drives (USB or similar)
- Server-based cryptographic operations: signing, encryption, and decryption happen in memory, reducing key exposure
- Automatic passphrase prompt when mounting the external drive.
- Detachable signatures or encryption of files using your private key, stored only on the external drive
- Cross-platform:
- Windows uses a TCP socket (default port 65432)
- macOS and Linux use a Unix Domain Socket (
/tmp/phpgp.sockby default)
- PID management in an OS-specific cache directory (e.g.,
%LOCALAPPDATA%\phpgpon Windows,~/Library/Caches/phpgpon macOS,~/.cache/phpgpon Linux)
Requirements
- Python 3.7+ (recommended)
- GNUPG installed for local key imports (
load,unload) - psutil for detecting removable drives
- Click for building the CLI
- PGPy library for handling PGP operations in Python
Installation
Simply install it via pip:
pip install phpgp
or via pipx (recommended):
pipx install phpgp
Configuration
-
Create or Obtain Your PGP Keys:
-
For testing, you can generate keys with GnuPG:
gpg --full-generate-key gpg --armor --export-secret-keys > private_key.asc gpg --armor --export > public_key.asc
-
Alternatively, you may have existing keys in
.ascformat.
-
-
Configure an External Drive:
-
Make sure your USB drive or removable storage is mounted.
-
Run:
phpgp configure -
This will prompt you for paths to your private and public keys and copy them to the drive (e.g.,
X:\.phpgp\privateandX:\.phpgp\public). -
You can choose to delete the keys from your local disk for extra security (which is recommended).
-
Usage
Once installed, you have access to the phpgp command with various subcommands.
With phPGP you can either mount your USB or load keys from it.
When mounted, phPGP starts local server on your machine so you can do all PGP operations using this server and phpgp commands. This is better for security than just loading keys from USB.
Let's take a closer look at this.
Mounting and Unmounting
-
Mount:
phpgp mount- Select the external drive.
- Enter your passphrase to unlock your private key.
- The server starts in your terminal window.
- Optionally remove the key from the external drive.
-
Unmount:
phpgp unmount- Reads the server PID from the OS cache directory (e.g.,
~/.cache/phpgp/phpgp_server.pid). - Terminates the server process.
- Removes the PID file.
- Reads the server PID from the OS cache directory (e.g.,
Loading and Unloading Keys Locally
-
Load:
phpgp loadImports keys from your external drive into your local GPG instance, allowing you to use GnuPG commands locally with those keys.
-
Unload:
phpgp unloadRemoves the locally imported secret key from your GPG instance.
[!NOTE] For greater security, you can set your computer to delete the private key automatically with this command when you disconnect the USB. You can do the same with key downloading for convenience.
Cryptographic Operations
When you run the phPGP server via mount, you will want to perform operations using phpgp instead of gpg. This can be done with the appropriate commands: phpgp sign, phpgp encrypt, phpgp decrypt.
[!IMPORTANT] These commands will only work when the server is started with
phpgp mount.
Signing Files
-
Make sure the server is running (
phpgp mount). -
Sign a file:
phpgp sign path/to/file.txt
- Reads
file.txtin binary mode, base64-encodes it, sends it to the server. - A detached signature is saved to
file.txt.sig.
- Reads
-
Verify with GnuPG:
gpg --verify file.txt.sig file.txt
Encrypting and Decrypting Files
-
Encrypt:
phpgp encrypt path/to/file.txt path/to/recipient_public_key.asc
- The encrypted data is saved to
file.txt.enc.
- The encrypted data is saved to
-
Decrypt:
phpgp decrypt path/to/file.txt.enc
- Decrypted data is saved to
file.txt.enc.dec.
- Decrypted data is saved to
How It Works
- Configuration:
- Creates a
.phpgpfolder on your external drive containingprivateandpublicfolders with the appropriate keys.
- Creates a
- Mounting:
- Starts a background server (
phpgp.server) with your private key loaded in memory. - For security, you can remove the key files from the USB drive after mounting (recommended).
- Starts a background server (
- Server:
- Listens on a socket (TCP on Windows, Unix Domain Socket elsewhere).
- Receives JSON requests for
sign,encrypt,decrypt. - PGP operations happen in memory; the private key is never saved on local disk after mounting and never exposed until the
unmountoperation.
- Client Commands (subcommands in
cli.py):- Communicate with the server using JSON messages.
- Return results (signatures, encrypted data, decrypted data).
Project Structure
phpgp/
├── __init__.py # Metadata
├── cli.py # Main CLI implemented with Click
├── server.py # The server handling sign/encrypt/decrypt
└── utils.py # Helper functions for drive selection & cache path
Contributing
There is some issues now, feel free to fix them!
- Fork the repository on GitHub.
- Create a Feature Branch from
main. - Implement your feature or bug fix.
- Add Tests where and if applicable.
- Open a Pull Request describing your changes.
License
phpgp is licensed under the GNU General Public License v3.0.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
Enjoy secure and convenient PGP key usage with phPGP!
Metadata
Release files for phpgp 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| phpgp-1.1.0.tar.gz | 26.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| phpgp-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.2 kB
Release files / phpgp-1.1.0.tar.gz
| Download URL | phpgp-1.1.0.tar.gz |
|---|---|
| Size | 26.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d723df61aa67af4a4f92a3edd10f0a319fb66e974a87f142e741ce91dbbd2d21
|
|
BLAKE2b-256 checksum How to use checksums |
36025f20f3863e427eb70922a803b248adf2213c9c3df89392017dd23980d333
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 19, 2025.
Transparency logRelease files / phpgp-1.1.0-py3-none-any.whl
| Download URL | phpgp-1.1.0-py3-none-any.whl |
|---|---|
| Size | 26.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd522f96d189ff0d1971ec91db0388a433d9975b1895fd1fff732212db04aa81
|
|
BLAKE2b-256 checksum How to use checksums |
cdc7dd0dc59ccff7ce91b0d0bd498cc9e60fee7da7c7acd8520f9d3f42ab9ccf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 19, 2025.
Transparency log