pub fn encrypt(
    data: &[u8],
    key: &[u8]
) -> Result<Vec<u8>, symmetriccipher::SymmetricCipherError> {
    let mut iv = [0u8; 16];
    let mut f: Fortuna = SeedableRng::from_seed(data);
    f.fill_bytes(&mut iv);

    let mut encryptor = aes::cbc_encryptor(
            aes::KeySize::KeySize256,
            key,
            &iv,
            blockmodes::PkcsPadding);

    let mut final_result = Vec::<u8>::new();
    final_result.push_all(&iv);
    let mut read_buffer = buffer::RefReadBuffer::new(data);
    let mut buffer = [0; 4096];
    let mut write_buffer = buffer::RefWriteBuffer::new(&mut buffer);

    loop {
        let result = try!(encryptor.encrypt(
            &mut read_buffer,
            &mut write_buffer,
            true
        ));

        final_result.push_all(
            write_buffer.take_read_buffer().take_remaining()
        );

        match result {
            BufferResult::BufferUnderflow => break,
            BufferResult::BufferOverflow => {}
        }
    }

    Ok(final_result)
}
// ALL the encryption functions thx rust-crypto ^_^
ALL the encryption functions thx rust-crypto ^_^
ALL the encryption functions thx rust - crypto ^_^
pub fn encrypt(
    data: &[u8],
    key: &[u8]
) -> Result<Vec<u8>, symmetriccipher::SymmetricCipherError> {
    let mut iv = [0u8; 16];
    let mut f: Fortuna = SeedableRng::from_seed(data);
    f.fill_bytes(&mut iv);
    let mut encryptor = aes::cbc_encryptor(
            aes::KeySize::KeySize256,
            key,
            &iv,
            blockmodes::PkcsPadding);
    let mut final_result = Vec::<u8>::new();
    final_result.push_all(&iv);
    let mut read_buffer = buffer::RefReadBuffer::new(data);
    let mut buffer = [0; 4096];
    let mut write_buffer = buffer::RefWriteBuffer::new(&mut buffer);
    loop {
        let result = try!(encryptor.encrypt(
            &mut read_buffer,
            &mut write_buffer,
            true
        ));
        final_result.push_all(
            write_buffer.take_read_buffer().take_remaining()
        );
        match result {
            BufferResult::BufferUnderflow => break,
            BufferResult::BufferOverflow => {}
        }
    }
    Ok(final_result)
}
pub fn encrypt ( data : & [ u8 ] , key : & [ u8 ] ) -> Result < Vec < u8 > , symmetriccipher :: SymmetricCipherError > { let mut iv = [ 0u8 ; 16 ] ; let mut f : Fortuna = SeedableRng :: from_seed ( data ) ; f . fill_bytes ( & mut iv ) ; let mut encryptor = aes :: cbc_encryptor ( aes :: KeySize :: KeySize256 , key , & iv , blockmodes :: PkcsPadding ) ; let mut final_result = Vec :: < u8 > :: new ( ) ; final_result . push_all ( & iv ) ; let mut read_buffer = buffer :: RefReadBuffer :: new ( data ) ; let mut buffer = [ 0 ; 4096 ] ; let mut write_buffer = buffer :: RefWriteBuffer :: new ( & mut buffer ) ; loop { let result = try ! ( encryptor encrypt ( mut read_buffer mut write_buffer true ) ) ; final_result . push_all ( write_buffer . take_read_buffer ( ) . take_remaining ( ) ) ; match result { BufferResult :: BufferUnderflow => break , BufferResult :: BufferOverflow => { } } } Ok ( final_result ) }
ALL the encryption functions thx rust-crypto ^_^
ALL the encryption functions thx rust - crypto ^_^
data
&[u8]
key
&[u8]
data
&[u8]
key
&[u8]