| Crates.io | rscrypt |
| lib.rs | rscrypt |
| version | 0.2.1 |
| created_at | 2022-07-24 16:47:32.870872+00 |
| updated_at | 2023-03-25 11:37:19.887777+00 |
| description | rscrypt is a simple, fast, and secure encryption tool written in Rust. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 632082 |
| size | 10,493 |
The Rscrypt library provides functionality for creating and verifying password hashes.
To use the rscrypt library in your Rust project, add it as a dependency in your Cargo.toml file:
[dependencies]
rscrypt = "*"
Then, run cargo build to download and compile the dependencies.
Alternatively, you can use the following command for adding the latest version of the library:
cargo add rscrypt
Once installed, you can import the library in your Rust code using:
use rscrypt::{ Rscrypt };
That's it! You're ready to use the rscrypt library in your Rust project.
RscryptThis struct provides the following utility functions:
compare(src: &str, dst: &str) -> boolThis function compares the plaintext password string src with the hashed password string dst. It returns true if they match, else false.
use rscrypt::{Rscrypt};
let salt = Rscrypt::gen_salt(10);
let hashed = Rscrypt::hash(&salt, "password");
assert!(Rscrypt::compare("password", &hash));
gen_salt(cost: usize) -> StringThis function generates a random salt value that can be used for hashing a password. The cost argument determines the number of computational rounds to perform during hashing.
use rscrypt::{Rscrypt};
let salt = Rscrypt::gen_salt(10);
let hashed = Rscrypt::hash(&salt, "password");
assert!(Rscrypt::compare("password", &hashed));
get_salt(hash: &str) -> Option<String>This function extracts the salt value used for hashing from the given hash string.
use rscrypt::{Rscrypt};
let hash = "iIBDWiEk0118e29VbozxVmoCscUzu6k05cKGFbtgogI=$rscrypt$0.2.0$10$rLBARHBrWKCsvACVvBAN7O";
let salt = Rscrypt::get_salt(&hash);
assert_eq!(salt, "$rscrypt$0.2.0$10$rLBARHBrWKCsvACVvBAN7O");
hash(salt: &str, unhashed_str: &str) -> StringThis function hashes the plaintext password string unhashed_str with the given salt value salt.
use rscrypt::{Rscrypt};
let hashed = Rscrypt::hash("$rscrypt$0.2.0$10$rLBARHBrWKCsvACVvBAN7O", "password");
assert_eq!(
hashed,
"iIBDWiEk0118e29VbozxVmoCscUzu6k05cKGFbtgogI=$rscrypt$0.2.0$10$rLBARHBrWKCsvACVvBAN7O"
);
is_valid_hash(hash: &str) -> boolThis function returns true if the given hash string is a valid hashed password string, else false.
use rscrypt::{Rscrypt};
let hash = "iIBDWiEk0118e29VbozxVmoCscUzu6k05cKGFbtgogI=$rscrypt$0.2.0$10$rLBARHBrWKCsvACVvBAN7O";
assert!(Rscrypt::is_valid_hash(&hash));
This project is licensed under the MIT License.