1 unstable release
0.1.2 | Sep 24, 2022 |
---|---|
0.1.1 |
|
0.1.0 |
|
#10 in #crypt
189 downloads per month
9KB
123 lines
libcrypt-rs - rust binding for POSIX crypt library (libcrypt)
How to use it
Add to the dependencies
section in your Cargo.toml
:
libcrypt-rs = "0.1.2"
Documentation
cargo
has cool feature for generating documentation:
- Run
cargo doc
- Open in web browser
target/doc/libcrypt_rs/index.html
Example
use libcrypt_rs::{Crypt, Encryptions};
fn main() {
let mut crypt_engine = Crypt::new();
crypt_engine.gen_salt(Encryptions::Sha256).expect("Salt generating failed");
crypt_engine.encrypt("1234".to_string()).expect("Encryption failed");
println!("Encrypted data: {}", crypt_engine.encrypted);
}
Notices
- Do not encrypt multiple data at the same time, otherwise can cause segmentation fault.
lib.rs
:
rust binding for POSIX crypt library (libcrypt)
Example
// Import Crypt struct and Encryptions enum.
use libcrypt_rs::{Crypt, Encryptions};
fn main() {
// Create new instance of Crypt object.
let mut engine = Crypt::new();
// Generate new encryption salt for sha256crypt encryption algorithm.
engine.gen_salt(Encryptions::Sha256).expect("Salt generation failed");
// Encrypt "1234" string.
engine.encrypt("1234".to_string()).expect("Encryption failed");
// Encrypted data is stored in engine.encrypted. Let's print it to stdout.
println!("Encrypted data: '{}'", engine.encrypted);
}