D4 PGP Extension
A powerful VS Code extension for PGP encryption and decryption, providing seamless integration with the d4 Python library for secure file and text handling.
✨ Features
- 🔐 File Encryption/Decryption: Interactive file picker for encrypting and decrypting files with PGP symmetric encryption
- 📝 Text Encryption/Decryption: Encrypt and decrypt text content directly in VS Code editor
- 🔑 Smart Passphrase Management: Auto-load from
PGP_PASSKEY environment variable or set manually
- ⚙️ Auto-Configuration: Automatically detects Python path, installs d4 module, and configures GPG binary
- 📊 Status Monitoring: Real-time status bar indicator showing extension readiness
- 📋 Comprehensive Logging: Detailed logging for debugging and monitoring
- 💾 Flexible Save Options: Decrypt files and choose when/where to save the decrypted content
🚀 Quick Start
- Install the extension from VSIX or VS Code Marketplace
- Set environment variable (optional but recommended):
# Windows PowerShell
$env:PGP_PASSKEY = "your-passphrase"
# Or set permanently
[System.Environment]::SetEnvironmentVariable('PGP_PASSKEY', 'your-passphrase', 'User')
- Reload VS Code - Extension will auto-configure and load passphrase
- Start encrypting/decrypting files and text!
📋 Commands
File Operations
D4 PGP: Encrypt File - Select any file to encrypt (creates .gpg file)
D4 PGP: Decrypt File - Select encrypted .gpg file to decrypt (shows content in editor, save when ready)
Text Operations
D4 PGP: Encrypt Text - Encrypt selected text or enter text to encrypt
D4 PGP: Decrypt Text - Decrypt selected encrypted text
Configuration & Management
D4 PGP: Set Passphrase - Manually set or update PGP passphrase
D4 PGP: Configure PGP - Configure Python path, GPG binary, secrets file, and log level
D4 PGP: Show PGP Status - Display current status and configuration
D4 PGP: View Logs - Open the extension output channel for detailed logs
🎯 Usage Workflows
Encrypting a File
- Run
D4 PGP: Encrypt File from Command Palette (Ctrl+Shift+P)
- Select the file you want to encrypt
- Encrypted
.gpg file is created in the same directory
- Choose to open encrypted file or show in file explorer
Decrypting a File
- Run
D4 PGP: Decrypt File from Command Palette
- Select the
.gpg file to decrypt
- Decrypted content appears in a new editor tab
- Click "Save As..." when ready to save, or just close without saving
- Editor Context: Right-click in editor to access encryption/decryption commands
- Explorer Context: Right-click files in explorer to encrypt/decrypt directly
Configuration
The extension can be configured via VS Code settings:
{
"d4-pgp.pythonPath": "", // Path to Python executable (auto-detect if empty)
"d4-pgp.gpgBinary": "", // Path to GPG binary (auto-detect if empty)
"d4-pgp.defaultSecretsFile": "", // Default secrets file path
"d4-pgp.logLevel": "info" // Log level: debug, info, warning, error
}
📦 Requirements
The extension automatically installs and configures most requirements, but you may need:
- Python 3.9+ (auto-detected from system)
- d4 Python package (auto-installed from local repo or GitHub)
- GnuPG (bundled with d4 package - no separate installation needed on Windows)
Manual Installation (if needed)
If auto-installation fails, install manually:
# Install d4 Python package
pip install d4
# Or install from local repository
cd d:\myCode\gitHub\d4
pip install -e .
# Verify installation
python -c "from d4.d4_pgp import get_gpg_exe; print(get_gpg_exe())"
Windows:
- GPG binary is bundled with d4 package (no separate installation needed)
- Python path auto-detected using
py launcher
- Full Python executable path shown in configuration
macOS/Linux:
- May need to install GnuPG separately:
brew install gnupg or apt-get install gnupg
- Python path auto-detected from system
🔒 Security Notes
- Passphrase Storage: Passphrases stored in memory only, cleared on extension deactivation
- Environment Variable:
PGP_PASSKEY is read from environment but never written
- Encryption Method: Uses symmetric PGP encryption with AES-256
- Temporary Files: Python scripts created in temp directory and deleted after execution
- File Path Security: All file paths normalized to prevent injection attacks
- No Persistent Storage: Extension does not store any sensitive information on disk
🛠️ Troubleshooting
Extension Not Activating
- Check Output panel:
View > Output > D4 PGP Manager
- Look for initialization errors
- Verify Python is installed:
python --version or py --version
"PGP client not ready" Error
- Check if passphrase is set: Run
D4 PGP: Set Passphrase
- Or set
PGP_PASSKEY environment variable and reload VS Code
- Check logs for initialization errors
"d4 module not found" Error
# Verify d4 installation
python -c "import d4.d4_pgp"
# Reinstall if needed
pip install d4 --force-reinstall
File Decryption Fails with Unicode Error
- Fixed in latest version - file paths are now properly normalized
- Update to latest extension version
- If issue persists, check Output logs for details
GPG Binary Not Found
- Windows: GPG is bundled with d4 package (auto-configured)
- Check configuration:
D4 PGP: Show PGP Status
- Manually set GPG path if needed:
D4 PGP: Configure PGP > GPG Binary
Python Path Shows "py" Instead of Full Path
- Clear cached setting: Open Settings (JSON) and remove
"d4-pgp.pythonPath"
- Reload window:
Developer: Reload Window
- Extension will auto-detect full Python executable path
💻 Development
Building from Source
# Clone repository
git clone https://github.com/internetics-net/d4-extension.git
cd d4-extension
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Package extension
npm run package
Development Mode
# Watch mode for development
npm run watch
# Or press F5 in VS Code to launch Extension Development Host
Testing
# Run tests
npm test
# Lint code
npm run lint
See TESTING.md for comprehensive testing guide.
📄 License
MIT License - see LICENSE.txt for details
🤝 Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
📞 Support
For issues and support:
🙏 Acknowledgments
Built with the d4 Python library for PGP operations.