wecanencrypt
Simple Rust OpenPGP library for encryption, signing, and key management, built on top of rpgp.
Features
- Key Generation: Create OpenPGP keys with various cipher suites (Cv25519, RSA2k, RSA4k, NIST P-256/P-384/P-521)
- Encryption/Decryption: Encrypt and decrypt files and byte streams
- Signing/Verification: Sign messages (inline, cleartext, detached) and verify signatures
- Key Parsing: Parse certificates from files or bytes, extract key information
- Keyring Support: Parse and export GPG keyrings
- SSH Key Export: Convert OpenPGP authentication keys to SSH public key format
- Network Operations: Fetch keys via WKD (Web Key Directory) and HKP keyservers
- DNS DANE: Fetch keys via OPENPGPKEY DNS records (RFC 7929)
- KeyStore: SQLite-backed key storage with search, card-key associations, and management capabilities
- Smart Card Support: Upload keys to YubiKey/OpenPGP cards, sign and decrypt on-card, discover which cards hold keys for a certificate, configure touch policies
Usage
use ;
// Generate a new key
let key = create_key_simple?;
let public_key = get_pub_key?;
// Encrypt data
let plaintext = b"Hello, World!";
let encrypted = encrypt_bytes?;
// Decrypt data
let decrypted = decrypt_bytes?;
assert_eq!;
Smart Card Usage
use ;
// Check for connected card
if is_card_connected
DNS DANE Key Discovery
Fetch OpenPGP keys published in DNS via OPENPGPKEY records (RFC 7929):
use fetch_key_by_email_from_dane;
// Uses the system DNS resolver by default
let cert = fetch_key_by_email_from_dane?;
// Or specify a resolver explicitly
let cert = fetch_key_by_email_from_dane?;
Running Tests
Run all tests in the tests/ directory
Or run specific test files:
# Individual test files
Or combine them:
Smart Card Tests
Smart card tests require a physical YubiKey or compatible OpenPGP smart card. These tests are ignored by default:
Note: Card tests automatically reset the card to factory defaults before each test.
Optional Features
keystore(default): SQLite-backed key storage with card-key associationsnetwork(default): WKD and HKP key fetchingcard: Smart card support (requireslibpcsclite-devon Linux)dane: DNS DANE OPENPGPKEY key discovery (RFC 7929)draft-pqc: Post-quantum cryptography support
Release
GitHub publishing is wired through the tag-driven workflow in .github/workflows/publish.yml.
Before tagging a release, run:
Then:
- Update
versioninCargo.toml. - Push the version commit.
- Create and push a tag (e.g.
v0.7.0).
The publish workflow verifies that the tag matches the crate version, runs cargo publish --dry-run, and then publishes via crates.io trusted publishing.
The repository must be configured as a trusted publisher in crates.io before the first tagged release, with the GitHub Actions environment set to release to match .github/workflows/publish.yml.
The docs.rs build is configured to document keystore, network, card, and dane, while leaving draft-pqc out of the default published docs because it is experimental.
License
MIT