Crates.io | pgp-lib |
lib.rs | pgp-lib |
version | 1.0.0 |
source | src |
created_at | 2023-08-23 13:13:25.644728 |
updated_at | 2024-10-27 11:33:27.53719 |
description | High-level, asynchronous API for rPGP, a pure Rust implementation of OpenPGP |
homepage | https://pimalaya.org/ |
repository | https://github.com/pimalaya/core/tree/master/pgp/ |
max_upload_size | |
id | 951993 |
size | 50,197 |
High-level, asynchronous API for rPGP, a pure Rust implementation of OpenPGP.
The library comes with 6 cargo features, including 2 default ones:
tokio
: enables the tokio async runtimeasync-std
: enables the async-std async runtimerustls
: enables the rustls cryptonative-tls
: enables the native-tls cryptokey-discovery
: enables public key discovery mechanismsvendored
: compiles and statically link to a copy of non-Rust vendors like OpenSSLuse pgp::{decrypt, encrypt, gen_key_pair, read_sig_from_bytes, sign, verify};
#[tokio::main]
async fn main() {
let (alice_skey, alice_pkey) = gen_key_pair("alice@localhost", "").await.unwrap();
let (bob_skey, bob_pkey) = gen_key_pair("bob@localhost", "").await.unwrap();
let msg = b"message".to_vec();
// encrypt message with multiple recipients
let encrypted_msg = encrypt(vec![alice_pkey.clone(), bob_pkey], msg.clone())
.await
.unwrap();
// decrypt message
assert_eq!(msg, decrypt(alice_skey.clone(), "", encrypted_msg.clone()).await.unwrap());
assert_eq!(msg, decrypt(bob_skey, "", encrypted_msg.clone()).await.unwrap());
// sign message
let raw_sig = sign(alice_skey, "", msg.clone()).await.unwrap();
let sig = read_sig_from_bytes(raw_sig).await.unwrap();
// verify message
assert!(verify(alice_pkey, sig, msg).await.is_ok());
}
See the full API documentation on docs.rs.
Special thanks to the NLnet foundation and the European Commission that helped the project to receive financial support from various programs:
If you appreciate the project, feel free to donate using one of the following providers: