Crates.io | pgp |
lib.rs | pgp |
version | 0.14.2 |
source | src |
created_at | 2017-09-16 14:15:26.501652 |
updated_at | 2024-12-05 11:32:25.316479 |
description | OpenPGP implementation in Rust |
homepage | https://github.com/rpgp/rpgp |
repository | https://github.com/rpgp/rpgp |
max_upload_size | |
id | 31980 |
size | 3,438,410 |
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.
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.
> cargo add pgp
use std::fs;
use pgp::{SignedPublicKey, Message, Deserializable};
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 (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_content = msg.get_content().unwrap(); // actual message content
let msg_string = String::from_utf8(msg_content.unwrap()).expect("expect UTF8");
println!("Signed message: {:?}", msg_string);
use std::fs;
use pgp::{Deserializable, SignedPublicKey, SignedSecretKey};
use pgp::types::{PublicKeyTrait, SecretKeyTrait};
use pgp::crypto::hash::HashAlgorithm;
let priv_key_file = "key.sec.asc";
let pub_key_file = "key.asc";
let data = b"Hello world!";
// Create a new signature using the private key
let secret_key_string = fs::read_to_string(priv_key_file).expect("Failed to load secret key");
let signed_secret_key = SignedSecretKey::from_string(&secret_key_string).unwrap().0;
let new_signature = signed_secret_key.create_signature(|| "".to_string(), HashAlgorithm::default(), &data[..]).unwrap();
// Verify the signature using the public key
let key_string = fs::read_to_string(pub_key_file).expect("Failed to load public key");
let public_key = SignedPublicKey::from_string(&key_string).unwrap().0;
public_key.verify_signature(HashAlgorithm::default(), &data[..], &new_signature).unwrap();
Last updated September 2024
Implementation Status: IMPL_STATUS.md
Security Status: STATUS_SECURITY.md
Supported Platforms: PLATFORMS.md
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 :)
Checkout FAQ.md.
All crates in this repository support Rust 1.75 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.