pub struct Encryption;
Expand description

structure contains serveral methods to handle encryption

Implementations

encrypts the given plaintext with the given values with PBKDF2-SHA256-AES128CBC, defined in PKCS#5. Returns the ciphertext as Vec<u8>.

Error

if the encryption fails, or the given parameters are false.

Returns the ciphertext as Vec<u8>.

Error

if the encryption fails, or the given parameters are false.

decrypts the given ciphertext from the given values with PBKDF2-SHA256-AES128CBC, defined in PKCS#5. Returns the plaintext as Vec<u8>.

Error

if the decryption fails, or the given parameters are false.

decrypts the given ciphertext from the given values with PBKDF2-SHA256-AES256CBC, defined in PKCS#5. Returns the plaintext as Vec<u8>.

Error

if the decryption fails, or the given parameters are false.

method to encrypt a message with a key and and the given chunk number. This method should primary used to encrypt the given chunk data (if selected, then after the compression). Returns a the cipthertext as Vec<u8>.

Example
use zff::*;
use hex::ToHex;

fn main() -> Result<()> {
	let key = "01234567890123456789012345678912"; // 32Byte/256Bit Key
	let chunk_no = 1; // 12Byte/96Bit Key
	let message = "My message";
 
	let ciphertext = Encryption::encrypt_message(key, message, chunk_no, EncryptionAlgorithm::AES256GCMSIV)?;
 
	assert_eq!(ciphertext.encode_hex::<String>(), "32f1c2f8ff6594a07eda5a4eca6d198f4cda8935f171d2345888".to_string());
	Ok(())
}
Error

This method will fail, if the encryption fails.

method to decrypt a message with a key and and the given chunk number. This method should primary used to decrypt the given chunk data (if selected, then before the decompression). Returns a the plaintext as Vec<u8> of the given ciphertext.

Error

This method will fail, if the decryption fails.

Generates a new random key, with the given key size.

Example
use zff::*;
 
fn main() {
	let keysize = 256; //(e.g. for use as 256-Bit-AES-Key).
	let my_new_random_super_secret_key = Encryption::gen_random_key(keysize);
	//...
}

Generates a new random IV/Nonce as [u8; 16] for use in PBE header.

Generates a new random salt as [u8; 32] for use in PBE header.

Generates a new random IV/Nonce as [u8; 12] for use in encryption header.

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.

Should always be Self

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.