#private-key #memory #security #constant-time #secure #sensitive #password

secure-string

适用于在内存中存储敏感信息(如密码和私钥)的数据类型,具有恒等时间比较、mlock和归零功能

3个版本 (破坏性更新)

0.3.0 2023年9月30日
0.2.0 2023年9月30日
0.1.0 2023年9月30日

#699编码

Download history · Rust 包仓库 50/week @ 2024-03-13 · Rust 包仓库 14/week @ 2024-03-20 · Rust 包仓库 74/week @ 2024-03-27 · Rust 包仓库 49/week @ 2024-04-03 · Rust 包仓库 61/week @ 2024-04-10 · Rust 包仓库 24/week @ 2024-04-17 · Rust 包仓库 12/week @ 2024-04-24 · Rust 包仓库 69/week @ 2024-05-01 · Rust 包仓库 22/week @ 2024-05-08 · Rust 包仓库 30/week @ 2024-05-15 · Rust 包仓库 68/week @ 2024-05-22 · Rust 包仓库 295/week @ 2024-05-29 · Rust 包仓库 284/week @ 2024-06-05 · Rust 包仓库 203/week @ 2024-06-12 · Rust 包仓库 293/week @ 2024-06-19 · Rust 包仓库 364/week @ 2024-06-26 · Rust 包仓库

每月下载量1,241次
4 个crate中(3个直接使用)

Unlicense

37KB
777

Secure String

crates.io crates.io API Docs unlicense

Rust库,实现了一种数据类型(包括Vec<u8>和其他类型),适用于在内存中存储敏感信息(如密码和私钥)。受Haskell securemem 和 .NET SecureString 的启发。

特性

  • 支持各种安全数据类型:SecureVecSecureBytesSecureArraySecureStringSecureBox
  • 析构函数中自动使用 zeroize 归零
  • 如果可能,使用 mlockmadvise 进行保护
  • 格式化为 ***SECRET*** 以防止泄露到日志中
  • (可选)以字节字符串形式序列化为 Serde 支持的任何内容
  • (可选)对公共 unsafe API的编译时检查 preconditions

此crate基于 Val Packett 的 secstr,但修改为更符合Rust风格和更灵活。

用法

use secure_string::*;

let pw = SecureString::from("correct horse battery staple");

// Compared in constant time:
// (Obviously, you should store hashes in real apps, not plaintext passwords)
let are_pws_equal = pw == SecureString::from("correct horse battery staple".to_string()); // true

// Formatting, printing without leaking secrets into logs
let text_to_print = format!("{}", SecureString::from("hello")); // "***SECRET***"

// Clearing memory
// THIS IS DONE AUTOMATICALLY IN THE DESTRUCTOR
// (but you can force it)
let mut my_sec = SecureString::from("hello");
my_sec.zero_out();
// (It also sets the length to 0)
assert_eq!(my_sec.unsecure(), "");

小心使用 SecureString::from:如果您有一个借用字符串,它将被复制。
如果您有一个 Vec<u8>,请使用 SecureString::new

许可证

这是一款免费且不受限制的软件,已发布到公共领域。
更多信息,请参阅 UNLICENSE 文件或 unlicense.org

依赖项

~245KB