31个版本

新版本 0.13.2 2024年8月17日
0.13.1 2024年6月30日
0.12.0-alpha.32024年5月31日
0.12.0-alpha.12024年3月17日
0.1.0 2017年9月16日

#51 in 加密学

Download history 5876/week @ 2024-04-30 5552/week @ 2024-05-07 6769/week @ 2024-05-14 8871/week @ 2024-05-21 8671/week @ 2024-05-28 11377/week @ 2024-06-04 11427/week @ 2024-06-11 11579/week @ 2024-06-18 10837/week @ 2024-06-25 11332/week @ 2024-07-02 11526/week @ 2024-07-09 13348/week @ 2024-07-16 14465/week @ 2024-07-23 16479/week @ 2024-07-30 14510/week @ 2024-08-06 15137/week @ 2024-08-13

63,479 每月下载次数
用于 53 个crate(30个直接使用)

MIT/Apache

1.5MB
16K SLoC

rPGP


使用纯Rust实现OpenPGP,许可宽松

rPGP是遵循主要RFC的OpenPGP的纯Rust实现

有关实现的PGP功能的更多详细信息,请参阅 IMPL_STATUS.md

它提供灵活的低级API,并以尽可能兼容的方式允许用户构建高级PGP工具。此外,它完全支持Autocrypt 1.1电子邮件加密规范所需的所有功能。

用法

> 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);

使用OpenPGP密钥对生成和验证分离的签名

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();

当前状态

最后更新 2024年4月

使用rPGP的用户和库

  • Delta Chat:跨平台消息应用,通过电子邮件工作
  • rpm:解析和创建RPM文件的纯Rust库
  • rpgpie:实验性高级OpenPGP API
  • rsop:基于rPGP和rpgpie的SOP CLI工具
  • debian-packaging:处理Debian包的库crate

您的项目不在这里?请发送PR :)

常见问题解答

查看 FAQ.md

最低支持的Rust版本(MSRV)

本存储库中的所有crate都支持Rust 1.74或更高版本。在未来的最低支持版本中,Rust可以更改,但将以小版本号提升的方式完成。

许可证

该项目采用以下任一许可证:

您可选择。

贡献

除非您明确声明,否则根据Apache-2.0许可证定义的任何有意提交以包含在本项目中的贡献,都应按上述方式双许可,没有任何附加条款或条件。

依赖项

约15-23MB
~308K SLoC