pub struct Encryption;Expand description
structure contains serveral methods to handle encryption
Implementations§
Source§impl Encryption
impl Encryption
Sourcepub fn encrypt_pbkdf2sha256_aes128cbc(
iterations: u32,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt_pbkdf2sha256_aes128cbc( iterations: u32, salt: &[u8; 32], aes_iv: &[u8; 16], password: impl AsRef<[u8]>, plaintext: &[u8], ) -> Result<Vec<u8>>
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.
Sourcepub fn encrypt_pbkdf2sha256_aes256cbc(
iterations: u32,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt_pbkdf2sha256_aes256cbc( iterations: u32, salt: &[u8; 32], aes_iv: &[u8; 16], password: impl AsRef<[u8]>, plaintext: &[u8], ) -> Result<Vec<u8>>
Returns the ciphertext as Vec<u8>.
§Error
if the encryption fails, or the given parameters are false.
Sourcepub fn decrypt_pbkdf2sha256_aes128cbc(
iterations: u32,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
ciphertext: &[u8],
) -> Result<Vec<u8>>
pub fn decrypt_pbkdf2sha256_aes128cbc( iterations: u32, salt: &[u8; 32], aes_iv: &[u8; 16], password: impl AsRef<[u8]>, ciphertext: &[u8], ) -> Result<Vec<u8>>
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.
Sourcepub fn decrypt_pbkdf2sha256_aes256cbc(
iterations: u32,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
ciphertext: &[u8],
) -> Result<Vec<u8>>
pub fn decrypt_pbkdf2sha256_aes256cbc( iterations: u32, salt: &[u8; 32], aes_iv: &[u8; 16], password: impl AsRef<[u8]>, ciphertext: &[u8], ) -> Result<Vec<u8>>
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.
Sourcepub fn encrypt_scrypt_aes128cbc(
logn: u8,
r: u32,
p: u32,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt_scrypt_aes128cbc( logn: u8, r: u32, p: u32, salt: &[u8; 32], aes_iv: &[u8; 16], password: impl AsRef<[u8]>, plaintext: &[u8], ) -> Result<Vec<u8>>
encrypts the given plaintext with the given values with Scrypt-AES128CBC.
Returns the ciphertext as Vec<u8>.
§Error
if the encryption fails, or the given parameters are false.
Sourcepub fn encrypt_scrypt_aes256cbc(
logn: u8,
r: u32,
p: u32,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt_scrypt_aes256cbc( logn: u8, r: u32, p: u32, salt: &[u8; 32], aes_iv: &[u8; 16], password: impl AsRef<[u8]>, plaintext: &[u8], ) -> Result<Vec<u8>>
encrypts the given plaintext with the given values with Scrypt-AES256CBC.
Returns the ciphertext as Vec<u8>.
§Error
if the encryption fails, or the given parameters are false.
Sourcepub fn decrypt_scrypt_aes128cbc(
logn: u8,
r: u32,
p: u32,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn decrypt_scrypt_aes128cbc( logn: u8, r: u32, p: u32, salt: &[u8; 32], aes_iv: &[u8; 16], password: impl AsRef<[u8]>, plaintext: &[u8], ) -> Result<Vec<u8>>
decrypts the given ciphertext with the given values with Scrypt-AES128CBC.
Returns the plaintext as Vec<u8>.
§Error
if the encryption fails, or the given parameters are false.
Sourcepub fn decrypt_scrypt_aes256cbc(
logn: u8,
r: u32,
p: u32,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn decrypt_scrypt_aes256cbc( logn: u8, r: u32, p: u32, salt: &[u8; 32], aes_iv: &[u8; 16], password: impl AsRef<[u8]>, plaintext: &[u8], ) -> Result<Vec<u8>>
decrypts the given ciphertext with the given values with Scrypt-AES256CBC.
Returns the plaintext as Vec<u8>.
§Error
if the encryption fails, or the given parameters are false.
Sourcepub fn encrypt_message<K, M, A>(
key: K,
message: M,
chunk_no: u64,
algorithm: A,
) -> Result<Vec<u8>>
pub fn encrypt_message<K, M, A>( key: K, message: M, chunk_no: u64, algorithm: A, ) -> Result<Vec<u8>>
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.
Sourcepub fn decrypt_message<K, M, A>(
key: K,
message: M,
chunk_no: u64,
algorithm: A,
) -> Result<Vec<u8>>
pub fn decrypt_message<K, M, A>( key: K, message: M, chunk_no: u64, algorithm: A, ) -> Result<Vec<u8>>
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.
Sourcepub fn gen_random_key(length: usize) -> Vec<u8> ⓘ
pub fn gen_random_key(length: usize) -> Vec<u8> ⓘ
Generates a new random key, with the given key size.
§Example
use zff::*;
let keysize = 256; //(e.g. for use as 256-Bit-AES-Key).
let my_new_random_super_secret_key = Encryption::gen_random_key(keysize);
//...Sourcepub fn gen_random_iv() -> [u8; 16]
pub fn gen_random_iv() -> [u8; 16]
Generates a new random IV/Nonce as [u8; 16] for use in PBE header.
Sourcepub fn gen_random_salt() -> [u8; 32]
pub fn gen_random_salt() -> [u8; 32]
Generates a new random salt as [u8; 32] for use in PBE header.
Sourcepub fn gen_random_header_nonce() -> [u8; 12]
pub fn gen_random_header_nonce() -> [u8; 12]
Generates a new random IV/Nonce as [u8; 12] for use in encryption header.
Auto Trait Implementations§
impl Freeze for Encryption
impl RefUnwindSafe for Encryption
impl Send for Encryption
impl Sync for Encryption
impl Unpin for Encryption
impl UnwindSafe for Encryption
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more