Struct zff::Encryption
source · [−]pub struct Encryption;Expand description
structure contains serveral methods to handle encryption
Implementations
sourceimpl Encryption
impl Encryption
sourcepub fn encrypt_pbkdf2sha256_aes128cbc(
iterations: u16,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
plaintext: &[u8]
) -> Result<Vec<u8>>
pub fn encrypt_pbkdf2sha256_aes128cbc(
iterations: u16,
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: u16,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
plaintext: &[u8]
) -> Result<Vec<u8>>
pub fn encrypt_pbkdf2sha256_aes256cbc(
iterations: u16,
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: u16,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
ciphertext: &[u8]
) -> Result<Vec<u8>>
pub fn decrypt_pbkdf2sha256_aes128cbc(
iterations: u16,
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: u16,
salt: &[u8; 32],
aes_iv: &[u8; 16],
password: impl AsRef<[u8]>,
ciphertext: &[u8]
) -> Result<Vec<u8>>
pub fn decrypt_pbkdf2sha256_aes256cbc(
iterations: u16,
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_message<K, M, A>(
key: K,
message: M,
chunk_no: u64,
algorithm: A
) -> Result<Vec<u8>> where
K: AsRef<[u8]>,
M: AsRef<[u8]>,
A: Borrow<EncryptionAlgorithm>,
pub fn encrypt_message<K, M, A>(
key: K,
message: M,
chunk_no: u64,
algorithm: A
) -> Result<Vec<u8>> where
K: AsRef<[u8]>,
M: AsRef<[u8]>,
A: Borrow<EncryptionAlgorithm>,
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>> where
K: AsRef<[u8]>,
M: AsRef<[u8]>,
A: Borrow<EncryptionAlgorithm>,
pub fn decrypt_message<K, M, A>(
key: K,
message: M,
chunk_no: u64,
algorithm: A
) -> Result<Vec<u8>> where
K: AsRef<[u8]>,
M: AsRef<[u8]>,
A: Borrow<EncryptionAlgorithm>,
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::*;
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);
//...
}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 RefUnwindSafe for Encryption
impl Send for Encryption
impl Sync for Encryption
impl Unpin for Encryption
impl UnwindSafe for Encryption
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more