2个版本
| 0.1.2 | 2024年2月10日 |
|---|---|
| 0.1.1 | 2024年1月30日 |
#1058 in 密码学
35KB
602 行
CryptGuard:签名编程库
简介
CryptGuard:签名是一个综合性的密码学库,提供强大的签名和验证功能。它面向开发者,使应用程序能够应对未来的数字安全挑战。拥抱CryptGuard:签名,成为您在数字领域保护隐私的可靠盟友。
先决条件
确保您的系统安装了最新稳定的Rust、Cargo和Tokio运行时环境。
使用方法
新功能:Dilithium
CryptGuard:签名中的 dilithium 功能引入了Dilithium算法,这是一种后量子密码学签名方法。此功能为可选功能,可以在您的 Cargo.toml 中启用。
使用Dilithium签名消息
要使用Dilithium签名消息,
#[cfg(feature = "dilithium")]
#[tokio::main]
async fn main() {
#[cfg(feature = "dilithium")]
{
let mut sign = SignDilithium::new().unwrap();
let message = b"Hello, this is a test message";
// Sign the message
let signed_message = sign.sign_msg(message).await.expect("Failed to sign message with Dilithium");
// Print the signed message
println!("Signed message with Dilithium: {:?}", signed_message);
}
}
使用Dilithium验证签名消息
要验证签名消息,
#[cfg(feature = "dilithium")]
#[tokio::main]
async fn main() {
#[cfg(feature = "dilithium")]
{
let mut sign = SignDilithium::new().unwrap();
let message = b"Hello, this is a test message";
// Sign the message
let signed_message = sign.sign_msg(message).await.expect("Failed to sign message");
// Verify the signed message
let verification_result = sign.verify_msg(message).await.expect("Failed to verify message");
// Check the verification result
assert!(verification_result, "Verification failed for the signed message with Dilithium");
}
}
使用Dilithium签名文件
要使用Dilithium签名文件,
#[cfg(feature = "dilithium")]
#[tokio::main]
async fn main() {
#[cfg(feature = "dilithium")]
{
let mut sign = SignDilithium::new().unwrap();
let file_path = PathBuf::from("path/to/your/file.txt");
// Sign the file
let signed_file = sign.sign_file(file_path.clone()).await.expect("Failed to sign file with Dilithium");
// Print the result
println!("Signed file with Dilithium: {:?}", signed_file);
}
}
以下示例展示了在CryptGuard:签名中使用 dilithium 功能进行消息和文件的签名和验证,展示了库在后量子密码学方面的能力。
签名消息
要签名消息,
#[tokio::main]
async fn main() {
let mut sign = Sign::new().unwrap();
let message = b"Hello, this is a test message";
// Sign the message
let signed_message = sign.sign_msg(message).await.expect("Failed to sign message");
// Print the signed message
println!("Signed message: {:?}", signed_message);
}
签名文件
要签名文件,
#[tokio::main]
async fn main() {
let mut sign = Sign::new().unwrap();
let file_path = PathBuf::from("path/to/your/file.txt");
// Sign the file
let signed_file = sign.sign_file(file_path.clone()).await.expect("Failed to sign file");
// Print the result
println!("Signed file content: {:?}", signed_file);
}
依赖项
CryptGuard:签名依赖于几个外部crate,具体在 Cargo.toml 中指定
aes: 0.8.3tokio: 1.35.1 (带有full功能)colored: 2.1.0env: 0.0.0hex: 0.4.3hmac: 0.12.1indicatif: 0.17.7pqcrypto-falcon: 0.3.0pqcrypto-dilithium: 0.5.0pqcrypto-kyber: 0.8.0pqcrypto-traits: 0.3.5rand: 0.8.5sha2: 0.10.8tempfile: 3.9.0
许可证
CryptGuard:签名采用MIT许可证。完整的许可证文本可在仓库中的 LICENSE 文件中找到。
You now have the complete README.md content with the updated examples for CryptGuard.
依赖项
~25–40MB
~752K SLoC