Expand description
§WeCanEncrypt
A simple Rust OpenPGP library for encryption, signing, and key management using rpgp.
This library provides a functional API for common OpenPGP operations, including:
- Key Generation: Create RSA, Curve25519, or NIST curve keys
- Encryption/Decryption: Encrypt to one or multiple recipients
- Signing/Verification: Create and verify signatures
- Certificate Management: Parse, modify, and export certificates
- Key Storage: SQLite-backed keystore (optional feature)
§Migrating to 0.6.0
§Breaking changes
-
GeneratedKey.secret_keyis nowZeroizing<Vec<u8>>(wasVec<u8>). Secret key bytes are securely erased from memory on drop.ZeroizingimplementsDeref<Target = Vec<u8>>, so most code works unchanged. If you need aVec<u8>, call.to_vec(). -
CertificateInfo.user_idsis nowVec<UserIDInfo>(wasVec<String>). Each UID now includesvalue(the string),revoked(bool), andcertifications(third-party signatures). Access the UID string via.value(e.g.,info.user_ids[0].value). -
decrypt_with_key()now takes anallow_legacy: boolparameter. Passfalseto reject integrity-unprotected SED packets (recommended). Passtrueonly for historical pre-2007 data. -
decrypt_bytes()no longer decrypts legacy SED packets by default. Usedecrypt_bytes_legacy()for messages without integrity protection. -
Verification now rejects revoked keys. Signatures from revoked keys or subkeys return
false. Expired keys can still verify old signatures (by design, per OpenPGP semantics).
§Quick Start
use wecanencrypt::*;
// Generate a new Curve25519 key (fast)
let key = create_key_simple("password", &["Alice <alice@example.com>"]).unwrap();
// Encrypt a message
let ciphertext = encrypt_bytes(key.public_key.as_bytes(), b"Hello!", true).unwrap();
// Decrypt it
let plaintext = decrypt_bytes(&key.secret_key, &ciphertext, "password").unwrap();
assert_eq!(plaintext, b"Hello!");§Cipher Suites
The library supports multiple cipher suites:
| Suite | Primary Key | Encryption Subkey | Speed |
|---|---|---|---|
Cv25519 (default) | EdDSA Legacy | ECDH Curve25519 | Fast |
Cv25519Modern | Ed25519 (RFC 9580) | X25519 | Fast |
NistP256 | ECDSA P-256 | ECDH P-256 | Fast |
NistP384 | ECDSA P-384 | ECDH P-384 | Fast |
NistP521 | ECDSA P-521 | ECDH P-521 | Fast |
Rsa2k | RSA 2048-bit | RSA 2048-bit | Slow |
Rsa4k | RSA 4096-bit | RSA 4096-bit | Very Slow |
§Features
keystore: Enable SQLite-backed key storage (requiresrusqlite)network: Enable network operations for fetching keys from keyservers
§Design
This library uses a functional API - all operations are standalone functions
that take certificate data as &[u8]. This provides maximum flexibility
and avoids the overhead of wrapper types.
Re-exports§
pub use keystore::decrypt_bytes_from_store;pub use keystore::decrypt_file_from_store;pub use keystore::encrypt_bytes_from_store;pub use keystore::encrypt_bytes_to_multiple_from_store;pub use keystore::encrypt_file_from_store;pub use keystore::encrypt_file_to_multiple_from_store;pub use keystore::sign_bytes_detached_from_store;pub use keystore::sign_bytes_from_store;pub use keystore::sign_file_detached_from_store;pub use keystore::sign_file_from_store;pub use keystore::verify_bytes_detached_from_store;pub use keystore::verify_bytes_from_store;pub use keystore::verify_file_detached_from_store;pub use keystore::verify_file_from_store;pub use keystore::KeyStore;pub use pgp;
Modules§
Structs§
- Available
Subkey - Information about an available (valid, non-expired, non-revoked) subkey.
- Certificate
Info - Parsed certificate information.
- Generated
Key - Result of key generation.
- KeyCipher
Details - Detailed cipher information for a key component.
- RsaPublic
Key - RSA public key components for external verification.
- Subkey
Flags - Flags indicating which subkeys to generate or operate on.
- Subkey
Info - Information about a subkey.
- UIDCertification
- Information about a certification on a User ID.
- UserID
Info - Information about a User ID on a certificate.
Enums§
- Certification
Type - Certification types for key signing.
- Cipher
Suite - Cipher suite options for key generation.
- Error
- The main error type for wecanencrypt operations.
- KeyType
- The type/purpose of a key.
- Signing
Public Key - Public key for signing verification (algorithm-specific).
- SshHash
Algorithm - Hash algorithm for SSH signing operations.
- SshSign
Result - The algorithm and raw signature bytes from an SSH signing operation.
Functions§
- add_uid
- Add a new User ID to a certificate.
- bytes_
encrypted_ for - Get the key IDs that a message was encrypted for.
- certify_
key - Certify another key with this key (key signing).
- create_
key - Generate a new OpenPGP key pair.
- create_
key_ simple - Generate a key with default settings (Cv25519, all subkeys).
- decrypt_
bytes - Decrypt bytes using a secret key.
- decrypt_
bytes_ legacy - Decrypt bytes, allowing legacy SED (no integrity protection) messages.
- decrypt_
file - Decrypt a file using a secret key.
- decrypt_
reader_ to_ file - Decrypt data from a reader to a file.
- encrypt_
bytes - Encrypt bytes to a single recipient.
- encrypt_
bytes_ to_ multiple - Encrypt bytes to multiple recipients.
- encrypt_
file - Encrypt a file to a single recipient.
- encrypt_
file_ to_ multiple - Encrypt a file to multiple recipients.
- encrypt_
reader_ to_ file - Encrypt data from a reader to a file.
- export_
keyring_ armored - Export multiple certificates to an armored keyring.
- export_
keyring_ file - Export multiple certificates to a keyring file.
- fetch_
key_ by_ email - Fetch a key from Web Key Directory (WKD) by email address.
- fetch_
key_ by_ email_ from_ dane - Fetch an OpenPGP key via DNS DANE OPENPGPKEY record (RFC 7929).
- fetch_
key_ by_ email_ from_ keyserver - Fetch a key from a VKS keyserver by email address.
- fetch_
key_ by_ fingerprint - Fetch a key from an HKP keyserver by fingerprint.
- fetch_
key_ by_ keyid - Fetch a key from an HKP keyserver by key ID.
- file_
encrypted_ for - Get the key IDs that a file was encrypted for.
- get_
all_ available_ subkeys - Get all available subkeys (valid, not expired, not revoked).
- get_
available_ authentication_ subkeys - Get available authentication subkeys (valid, not expired, not revoked).
- get_
available_ encryption_ subkeys - Get available encryption subkeys (valid, not expired, not revoked).
- get_
available_ signing_ subkeys - Get available signing subkeys (valid, not expired, not revoked).
- get_
key_ cipher_ details - Get cipher details for all keys in a certificate.
- get_
pub_ key - Export the public key as ASCII armor.
- get_
signing_ pubkey - Get signing public key components for external verification.
- get_
ssh_ pubkey - Convert a certificate’s authentication key to SSH public key format.
- has_
available_ encryption_ subkey - Check if a certificate has any available encryption subkeys.
- has_
available_ signing_ subkey - Check if a certificate has any available signing subkeys.
- merge_
keys - Merge two certificates (e.g., adding new signatures).
- parse_
cert_ bytes - Parse a certificate from bytes and extract its information.
- parse_
cert_ file - Parse a certificate from a file and extract its information.
- parse_
keyring_ bytes - Parse keyring data containing multiple certificates.
- parse_
keyring_ file - Parse a keyring file containing multiple certificates.
- revoke_
key - Revoke the entire key.
- revoke_
uid - Revoke a User ID on a certificate.
- sign_
bytes - Sign bytes with a binary signature (wrapping the message).
- sign_
bytes_ cleartext - Sign bytes with a cleartext signature.
- sign_
bytes_ detached - Create a detached signature for bytes.
- sign_
file - Sign a file to an output file (binary signature).
- sign_
file_ cleartext - Sign a file with cleartext signature.
- sign_
file_ detached - Create a detached signature for a file.
- ssh_
sign_ raw - Perform a raw SSH signature using a software authentication subkey.
- update_
password - Change the password on a secret key.
- update_
primary_ expiry - Update the primary key expiration time.
- update_
subkeys_ expiry - Update the expiration time for specific subkeys.
- verify_
and_ extract_ bytes - Verify and extract the original message from signed bytes.
- verify_
and_ extract_ file - Verify and extract a signed file to an output path.
- verify_
bytes - Verify a signed message (inline or cleartext signature).
- verify_
bytes_ detached - Verify a detached signature on bytes.
- verify_
file - Verify a signed file.
- verify_
file_ detached - Verify a detached signature on a file.
Type Aliases§
- Result
- A specialized Result type for wecanencrypt operations.