Crates.io | pgp |
lib.rs | pgp |
version | 0.17.0 |
created_at | 2017-09-16 14:15:26.501652+00 |
updated_at | 2025-09-25 11:24:38.237645+00 |
description | OpenPGP implementation in Rust |
homepage | https://github.com/rpgp/rpgp |
repository | https://github.com/rpgp/rpgp |
max_upload_size | |
id | 31980 |
size | 5,058,754 |
OpenPGP implemented in pure Rust, permissively licensed
rPGP is a pure Rust implementation of OpenPGP.
rPGP implements OpenPGP as specified in RFC9580, including the commonly used v4 formats, as well as the latest v6 key formats and AEAD encryption mechanisms. All formats specified in the historical RFCs RFC4880 and RFC6637, such as v3 keys and signatures, are supported as well.
See IMPL_STATUS.md
for more details on the implemented PGP features and
openpgp.md
for a rough taxonomy.
rPGP offers a flexible low-level API and gives users the ability to build higher level PGP tooling in the most compatible way possible. Additionally, it fully supports all functionality required by the Autocrypt 1.1 e-mail encryption specification.
rpm
: A pure rust library for parsing and creating RPM filesrpgpie
: An experimental high level OpenPGP APIrsop
: A SOP CLI tool based on rPGP and rpgpiedebian-packaging
: a library crate for dealing with Debian packagesDon't see your project here? Please send a PR :)
> cargo add pgp
use std::fs;
use pgp::composed::{Deserializable, Message, SignedPublicKey};
fn main() {
let pub_key_file = "key.asc";
let msg_file = "msg.asc";
let key_string = fs::read_to_string(pub_key_file).unwrap();
let (public_key, _headers_public) = SignedPublicKey::from_string(&key_string).unwrap();
let msg_string = fs::read_to_string(msg_file).unwrap();
let (mut msg, _headers_msg) = Message::from_string(&msg_string).unwrap();
// Verify this message
// NOTE: This assumes that the primary serves as the signing key, which is not always the case!
msg.verify(&public_key).unwrap();
let msg_string = msg.as_data_string().unwrap(); // actual message content
println!("Signed message: {msg_string:?}");
}
use std::time::SystemTime;
use pgp::composed::{Deserializable, SignedPublicKey, SignedSecretKey};
use pgp::packet::{SignatureConfig, SignatureType, Subpacket, SubpacketData};
use pgp::types::{KeyDetails, Password};
fn main() -> pgp::errors::Result<()> {
let priv_key_file = "key.sec.asc";
let data = b"Hello world!";
// -- Create a new signature using the private key --
let signed_secret_key = SignedSecretKey::from_armor_file(priv_key_file)?.0;
// Set up a signature configuration to create a binary data signature
let mut config = SignatureConfig::from_key(
rand::thread_rng(),
&signed_secret_key.primary_key,
SignatureType::Binary,
)?;
config.hashed_subpackets = vec![
Subpacket::regular(SubpacketData::IssuerFingerprint(
signed_secret_key.fingerprint(),
))?,
Subpacket::critical(SubpacketData::SignatureCreationTime(
SystemTime::now().into(),
))?,
];
config.unhashed_subpackets =
vec![Subpacket::regular(SubpacketData::Issuer(signed_secret_key.key_id()))?];
// Generate an OpenPGP signature packet (which is used as a "detached signature", in this context)
let signature = config
.sign(
&signed_secret_key.primary_key,
&Password::empty(),
&data[..],
)?;
// -- Verify the signature using the public key --
let pub_key_file = "key.asc";
let public_key = SignedPublicKey::from_armor_file(pub_key_file)?.0;
signature.verify(&public_key, &data[..])?;
Ok(())
}
bzip2
: Enables bzip2 supportasm
: Enables assembly based optimizationswasm
: Allows building for wasmmalformed-artifact-compat
: Be lenient towards some types of malformed artifacts (erroneously formed ECDH PKESK; invalidly short first partial body segments). Most users will NOT need this feature, should be disabled by default!draft-pqc
: Enables implementation of draft-ietf-openpgp-pqc-12 (This is unstable and can have breaking changes in patch releases. DO NOT USE IN PRODUCTION!)Last updated September 2024
IMPL_STATUS.md
STATUS_SECURITY.md
PLATFORMS.md
See FAQ.md
.
See openpgp.md
.
rPGP aims to make it easy for application developers to incorporate OpenPGP functionality into their projects.
Note that the OpenPGP format and its semantics are relatively complex. We recommend the text "OpenPGP for application developers" for initial orientation.
Independently, we welcome questions in the rPGP issue tracker.
rPGP offers abstractions for handling the formats and mechanisms specified in RFC 9580. However, it offers them as relatively low-level building blocks, and doesn't attempt to ensure that users can not apply them unsafely.
rPGP allows following almost all parts of the OpenPGP specification, but the APIs are low level building blocks and do not claim that using them is (a) secure or (b) following the OpenPGP specification
Using the building blocks in rPGP correctly and safely requires a solid understanding of OpenPGP and at least a basic understanding of cryptography.
For context, OpenPGP can be thought of as a multi-layered technology, roughly like this:
Of these layers, the OpenPGP RFC specifies 1-3, while 4 is not specified in detail.
Some work on formalizing OpenPGP semantics can be found in draft-gallagher-openpgp-signatures and draft-dkg-openpgp-revocation.
Analogous to the RFC, rPGP handles layers 1-3, but explicitly does not deal with 4. Applications that need OpenPGP semantics must implement them manually, or rely on additional libraries to deal with that layer.
NOTE: The rpgpie
library implements some of these high level OpenPGP semantics.
It may be useful either to incorporate in rPGP projects, or to study for reference.
rPGP can handle a wide range of OpenPGP artifacts. It offers support for almost all mechanisms in OpenPGP, both modern and those now considered legacy.
This explicitly includes artifacts that use historical algorithms, which are considered insecure given today's understanding.
rPGP doesn't ensure that application developers use appropriate cryptographic building blocks for their purposes (even though it generally produces appropriately modern artifacts, by default).
See "Overview of OpenPGP formats and mechanisms" for more details on the evolution of OpenPGP over time.
All crates in this repository support Rust 1.85 or higher. In future minimally supported version of Rust can be changed, but it will be done with a minor version bump.
RFC 9580 support for rPGP has been funded in part through NGI0 Core, a fund established by NLnet with financial support from the European Commission's Next Generation Internet programme.
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.