fn decrypt_aes(
    encrypted_data: &[u8],
    key: &[u8],
    iv: &[u8],
) -> ::std::result::Result<Vec<u8>, symmetriccipher::SymmetricCipherError> {
    let mut decryptor =
        aes::cbc_decryptor(aes::KeySize::KeySize256, key, iv, blockmodes::PkcsPadding);

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

    loop {
        let result = decryptor.decrypt(&mut read_buffer, &mut write_buffer, true)?;
        final_result.extend(
            write_buffer
                .take_read_buffer()
                .take_remaining()
                .iter()
                .map(|&i| i),
        );
        match result {
            BufferResult::BufferUnderflow => break,
            BufferResult::BufferOverflow => {}
        }
    }

    Ok(final_result)
}
/// Decrypts a buffer with the given key and iv using AES-256/CBC/Pkcs encryption.
///
/// This function is very similar to encrypt(), so, please reference
/// comments in that function. In non-example code, if desired, it is possible to
/// share much of the implementation using closures to hide the operation
/// being performed. However, such code would make this example less clear.
Decrypts a buffer with the given key and iv using AES-256/CBC/Pkcs encryption.
This function is very similar to encrypt(), so, please reference
comments in that function. In non-example code, if desired, it is possible to
share much of the implementation using closures to hide the operation
being performed. However, such code would make this example less clear.
Decrypts a buffer with the given key and iv using AES - 256 / CBC / Pkcs encryption . This function is very similar to encrypt () so please reference comments in that function . In non - example code if desired it is possible to share much of the implementation using closures to hide the operation being performed . However such code would make this example less clear .
fn decrypt_aes(
    encrypted_data: &[u8],
    key: &[u8],
    iv: &[u8],
) -> ::std::result::Result<Vec<u8>, symmetriccipher::SymmetricCipherError> {
    let mut decryptor =
        aes::cbc_decryptor(aes::KeySize::KeySize256, key, iv, blockmodes::PkcsPadding);
    let mut final_result = Vec::<u8>::new();
    let mut read_buffer = buffer::RefReadBuffer::new(encrypted_data);
    let mut buffer = [0; 4096];
    let mut write_buffer = buffer::RefWriteBuffer::new(&mut buffer);
    loop {
        let result = decryptor.decrypt(&mut read_buffer, &mut write_buffer, true)?;
        final_result.extend(
            write_buffer
                .take_read_buffer()
                .take_remaining()
                .iter()
                .map(|&i| i),
        );
        match result {
            BufferResult::BufferUnderflow => break,
            BufferResult::BufferOverflow => {}
        }
    }
    Ok(final_result)
}
fn decrypt_aes ( encrypted_data : & [ u8 ] , key : & [ u8 ] , iv : & [ u8 ] , ) -> :: std :: result :: Result < Vec < u8 > , symmetriccipher :: SymmetricCipherError > { let mut decryptor = aes :: cbc_decryptor ( aes :: KeySize :: KeySize256 , key , iv , blockmodes :: PkcsPadding ) ; let mut final_result = Vec :: < u8 > :: new ( ) ; let mut read_buffer = buffer :: RefReadBuffer :: new ( encrypted_data ) ; let mut buffer = [ 0 ; 4096 ] ; let mut write_buffer = buffer :: RefWriteBuffer :: new ( & mut buffer ) ; loop { let result = decryptor . decrypt ( & mut read_buffer , & mut write_buffer , true ) ? ; final_result . extend ( write_buffer . take_read_buffer ( ) . take_remaining ( ) . iter ( ) . map ( | & i | i ) , ) ; match result { BufferResult :: BufferUnderflow => break , BufferResult :: BufferOverflow => { } } } Ok ( final_result ) }
Decrypts a buffer with the given key and iv using AES-256/CBC/Pkcs encryption.
Decrypts a buffer with the given key and iv using AES - 256 / CBC / Pkcs encryption .
encrypted_data
&[u8]
key
&[u8]
iv
&[u8]
encrypted_data
&[u8]
key
&[u8]
iv
&[u8]