pub fn encrypt(data: &[u8]) -> BerylliumResult<EncryptData> {
    let cipher = Cipher::aes_256_cbc();
    let mut iv = vec![0; cipher.iv_len().unwrap()];     // 16 bytes
    rand::rand_bytes(&mut iv)?;
    let mut key = vec![0; cipher.key_len()];    // 32 bytes
    rand::rand_bytes(&mut key)?;
    let mut bytes = symm::encrypt(cipher, &key, Some(&iv), data)?;
    let hash = Sha256::digest(&bytes);
    // First block is IV
    let mut out = iv.clone();
    out.append(&mut bytes);

    Ok(EncryptData {
        key: key,
        data: out,
        hash: Vec::from(hash.as_slice()),
    })
}
/// Encrypt the given data with AES cipher (256 bits) in CBC mode
/// (with the initialization vector at the start). Also compute the
/// SHA-256 hash of the ciphertext.
Encrypt the given data with AES cipher (256 bits) in CBC mode
(with the initialization vector at the start). Also compute the
SHA-256 hash of the ciphertext.
Encrypt the given data with AES cipher ( 256 bits ) in CBC mode ( with the initialization vector at the start ) . Also compute the SHA - 256 hash of the ciphertext .
pub fn encrypt(data: &[u8]) -> BerylliumResult<EncryptData> {
    let cipher = Cipher::aes_256_cbc();
    let mut iv = vec![0; cipher.iv_len().unwrap()];     // 16 bytes
    rand::rand_bytes(&mut iv)?;
    let mut key = vec![0; cipher.key_len()];    // 32 bytes
    rand::rand_bytes(&mut key)?;
    let mut bytes = symm::encrypt(cipher, &key, Some(&iv), data)?;
    let hash = Sha256::digest(&bytes);
    // First block is IV
    let mut out = iv.clone();
    out.append(&mut bytes);
    Ok(EncryptData {
        key: key,
        data: out,
        hash: Vec::from(hash.as_slice()),
    })
}
pub fn encrypt ( data : & [ u8 ] ) -> BerylliumResult < EncryptData > { let cipher = Cipher :: aes_256_cbc ( ) ; let mut iv = vec ! [ 0 cipher iv_len ( ) unwrap ( ) ] ; // 16 bytes rand :: rand_bytes ( & mut iv ) ? ; let mut key = vec ! [ 0 cipher key_len ( ) ] ; // 32 bytes rand :: rand_bytes ( & mut key ) ? ; let mut bytes = symm :: encrypt ( cipher , & key , Some ( & iv ) , data ) ? ; let hash = Sha256 :: digest ( & bytes ) ; // First block is IV let mut out = iv . clone ( ) ; out . append ( & mut bytes ) ; Ok ( EncryptData { key : key , data : out , hash : Vec :: from ( hash . as_slice ( ) ) , } ) }
Encrypt the given data with AES cipher (256 bits) in CBC mode
(with the initialization vector at the start).
Encrypt the given data with AES cipher ( 256 bits ) in CBC mode ( with the initialization vector at the start ) .
data
&[u8]