#crypt #posix #binding #struct #libcrypt #encryptions

libcrypt-rs

rust binding for POSIX crypt library (libcrypt)

1 unstable release

0.1.2 Sep 24, 2022
0.1.1 Sep 24, 2022
0.1.0 Sep 24, 2022

#10 in #crypt

Download history 5/week @ 2024-09-23 9/week @ 2024-10-07 2/week @ 2024-10-14 119/week @ 2024-10-21 19/week @ 2024-10-28 28/week @ 2024-11-04 23/week @ 2024-11-11

189 downloads per month

Custom license

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);
}

No runtime deps