Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rust crate for secure handling of sensitive data.

License

NotificationsYou must be signed in to change notification settings

cot-rs/secure-string

 
 

Repository files navigation

crates.iocrates.ioAPI Docsunlicense

ARust library that implements a data type (wrapper aroundVec<u8> and other types) suitable for storing sensitive information such as passwords and private keys in memory.Inspired by Haskellsecuremem and .NETSecureString.

Featuring:

  • Supports various secure datatypes:SecureVec,SecureBytes,SecureArray,SecureString,SecureBox
  • automatically zeroing out in the destructor usingzeroize
  • mlock andmadvise protection if possible
  • formatting as***SECRET*** to prevent leaking into logs
  • (optionally) de/serializable into anythingSerde supports as a byte string
  • (optionally) compile-time checkedpreconditions for the publicunsafe API

This crate is based onsecstr by Val Packett, but modified to be a bit more rusty and versatile.

Usage

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 logslet text_to_print =format!("{}",SecureString::from("hello"));// "***SECRET***"// Clearing memory// THIS IS DONE AUTOMATICALLY IN THE DESTRUCTOR// (but you can force it)letmut my_sec =SecureString::from("hello");my_sec.zero_out();// (It also sets the length to 0)assert_eq!(my_sec.unsecure(),"");

Be careful withSecureString::from: if you have a borrowed string, it will be copied.
UseSecureString::new if you have aVec<u8>.

License

This is free and unencumbered software released into the public domain.
For more information, please refer to theUNLICENSE file orunlicense.org.

About

Rust crate for secure handling of sensitive data.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust100.0%

[8]ページ先頭

©2009-2025 Movatter.jp