pub struct Crypt {
    pub encrypted: String,
    /* private fields */
}
Expand description

Encryption struct.

Fields

encrypted: String

Stores encrypted data.

Implementations

Create new instance of Crypt object.

Set custom salt for encryption.

use libcrypt_rs::Crypt;
 
let mut engine = Crypt::new();
engine.set_salt("$1$N1TAWHQs".to_string()).expect("Setting custom salt failed");
 
println!("{}", engine.get_salt().unwrap());

Generate salt.

use libcrypt_rs::{Crypt, Encryptions};
 
let mut engine = Crypt::new();
engine.gen_salt(Encryptions::Sha256).expect("Salt generation failed");
 
println!("{}", engine.get_salt().unwrap());

Encrypt data. Encrypted data can be accessed in the encrypted field of Crypt struct.

use libcrypt_rs::{Crypt, Encryptions};
 
let mut engine = Crypt::new();
engine.gen_salt(Encryptions::Sha256).expect("Salt generation failed");
 
engine.encrypt("example_phrase".to_string()).expect("Encryption failed");
 
println!("Encrypted data: {}", engine.encrypted);

salt is a private field of Crypt struct, using this function.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.