pip install cryptographypython encrypt_secrets.pyFollow the prompts:
- Enter master passphrase (remember this!)
- Enter Gemini API Key
- Enter optional credentials (MongoDB, Twilio)
- File
secrets.encwill be created
streamlit run app.py- Click 🔐 Security tab
- Enter your passphrase
- Click 🔓 Load Secrets
- ✅ Done!
| File | Purpose |
|---|---|
crypto_simple.py |
AES-256-GCM encryption/decryption |
signing.py |
HMAC-SHA256 digital signatures |
encrypt_secrets.py |
CLI tool to create secrets.enc |
secrets.enc |
Encrypted secrets (binary) |
app.py |
Updated with Security tab |
.gitignore |
Updated to ignore secrets.enc |
- Algorithm: AES-256-GCM
- Key Derivation: scrypt (N=16384)
- Format: salt(16) + nonce(12) + ciphertext+tag
- Algorithm: HMAC-SHA256
- Output: Base64-encoded signatures
- Auto-generated: 256-bit signing secret
- Load secrets at runtime (no restart needed)
- Verify analysis signatures
- Hybrid mode support
from crypto_simple import load_encrypted
secrets = load_encrypted('secrets.enc', 'your-passphrase')
api_key = secrets['gemini_api_key']
signing_secret = secrets['signing_secret']from signing import sign_analysis
analysis = {
'email_id': '123',
'risk_score': 85,
'category': 'HIGH_RISK'
}
signing_secret = bytes.fromhex(secrets['signing_secret'])
signed = sign_analysis(analysis, signing_secret)
# signed now contains 'signature' fieldfrom signing import verify_analysis
is_valid = verify_analysis(signed, signing_secret)
print(f"Valid: {is_valid}") # True- Never commit secrets.enc - Already in .gitignore ✅
- Store passphrase securely - Use password manager
- Backup secrets.enc - Keep encrypted backup
- Use strong passphrase - 12+ characters recommended
- Rotate secrets - Every 90 days for production
# Test encryption
python -c "from crypto_simple import encrypt_data, decrypt_data; \
data = {'test': 'data'}; \
encrypted = encrypt_data(data, 'test'); \
print('✅ Encryption works!' if decrypt_data(encrypted, 'test') == data else '❌ Failed')"
# Test signing
python -c "from signing import sign, verify; \
record = {'id': '1'}; \
sig = sign(record, b'secret'); \
print('✅ Signing works!' if verify(record, sig, b'secret') else '❌ Failed')"See M3_SECURITY_GUIDE.md for:
- Detailed API reference
- Advanced usage examples
- Troubleshooting guide
- Security best practices
- Key rotation procedures
Problem: secrets.enc not found
Solution: Run python encrypt_secrets.py first
Problem: Decryption failed
Solution: Check passphrase (case-sensitive, no extra spaces)
Problem: Module not found: cryptography
Solution: Run pip install cryptography
Problem: Signature Invalid
Solution: Ensure signing secret matches and data wasn't modified
-
cryptographyinstalled -
secrets.enccreated - Can load secrets in Streamlit
- Security tab accessible
- Signature verification works
- Passphrase stored securely
Ready to use! 🎉
For questions, see M3_SECURITY_GUIDE.md or check code comments.